- .NET Clients: other versions:
- Introduction
- Installation
- Breaking changes
- API Conventions
- Elasticsearch.Net - Low level client
- NEST - High level client
- Troubleshooting
- Search
- Query DSL
- Full text queries
- Term level queries
- Exists Query Usage
- Fuzzy Date Query Usage
- Fuzzy Numeric Query Usage
- Fuzzy Query Usage
- Ids Query Usage
- Prefix Query Usage
- Date Range Query Usage
- Long Range Query Usage
- Numeric Range Query Usage
- Term Range Query Usage
- Regexp Query Usage
- Term Query Usage
- Terms Set Query Usage
- Terms List Query Usage
- Terms Lookup Query Usage
- Terms Query Usage
- Wildcard Query Usage
- Compound queries
- Joining queries
- Geo queries
- Specialized queries
- Span queries
- NEST specific queries
- Aggregations
- Metric Aggregations
- Average Aggregation Usage
- Boxplot Aggregation Usage
- Cardinality Aggregation Usage
- Extended Stats Aggregation Usage
- Geo Bounds Aggregation Usage
- Geo Centroid Aggregation Usage
- Geo Line Aggregation Usage
- Max Aggregation Usage
- Median Absolute Deviation Aggregation Usage
- Min Aggregation Usage
- Percentile Ranks Aggregation Usage
- Percentiles Aggregation Usage
- Rate Aggregation Usage
- Scripted Metric Aggregation Usage
- Stats Aggregation Usage
- String Stats Aggregation Usage
- Sum Aggregation Usage
- T Test Aggregation Usage
- Top Hits Aggregation Usage
- Top Metrics Aggregation Usage
- Value Count Aggregation Usage
- Weighted Average Aggregation Usage
- Bucket Aggregations
- Adjacency Matrix Usage
- Auto Date Histogram Aggregation Usage
- Children Aggregation Usage
- Composite Aggregation Usage
- Date Histogram Aggregation Usage
- Date Range Aggregation Usage
- Diversified Sampler Aggregation Usage
- Filter Aggregation Usage
- Filters Aggregation Usage
- Geo Distance Aggregation Usage
- Geo Hash Grid Aggregation Usage
- Geo Tile Grid Aggregation Usage
- Global Aggregation Usage
- Histogram Aggregation Usage
- Ip Range Aggregation Usage
- Missing Aggregation Usage
- Multi Terms Aggregation Usage
- Nested Aggregation Usage
- Parent Aggregation Usage
- Range Aggregation Usage
- Rare Terms Aggregation Usage
- Reverse Nested Aggregation Usage
- Sampler Aggregation Usage
- Significant Terms Aggregation Usage
- Significant Text Aggregation Usage
- Terms Aggregation Usage
- Variable Width Histogram Usage
- Pipeline Aggregations
- Average Bucket Aggregation Usage
- Bucket Script Aggregation Usage
- Bucket Selector Aggregation Usage
- Bucket Sort Aggregation Usage
- Cumulative Cardinality Aggregation Usage
- Cumulative Sum Aggregation Usage
- Derivative Aggregation Usage
- Extended Stats Bucket Aggregation Usage
- Max Bucket Aggregation Usage
- Min Bucket Aggregation Usage
- Moving Average Ewma Aggregation Usage
- Moving Average Holt Linear Aggregation Usage
- Moving Average Holt Winters Aggregation Usage
- Moving Average Linear Aggregation Usage
- Moving Average Simple Aggregation Usage
- Moving Function Aggregation Usage
- Moving Percentiles Aggregation Usage
- Normalize Aggregation Usage
- Percentiles Bucket Aggregation Usage
- Serial Differencing Aggregation Usage
- Stats Bucket Aggregation Usage
- Sum Bucket Aggregation Usage
- Matrix Aggregations
- Metric Aggregations
Ignoring properties
editIgnoring properties
editProperties on a POCO can be ignored for mapping purposes in a few ways:
-
Using the
Ignore
property on a derivedElasticsearchPropertyAttributeBase
type, such asTextAttribute
, applied to the property that should be ignored on the POCO -
Using the
Ignore
property onPropertyNameAttribute
applied to a property that should be ignored on the POCO -
Using the
.DefaultMappingFor<TDocument>(Func<ClrTypeMappingDescriptor<TDocument>, IClrTypeMapping<TDocument>> selector)
onConnectionSettings
-
Using an ignore attribute applied to the POCO property that is understood by
the
IElasticsearchSerializer
used, and inspected inside of theCreatePropertyMapping()
on the serializer. Using the builtinSourceSerializer
this would be theIgnoreProperty
This example demonstrates all ways, using the Ignore
property on the attribute to ignore the property
PropertyToIgnore
, the infer mapping to ignore the property AnotherPropertyToIgnore
and the
json serializer specific attribute to ignore the property either IgnoreProperty
or JsonIgnoredProperty
depending on which
SourceSerializer
we configured.
[ElasticsearchType(RelationName = "company")] public class CompanyWithAttributesAndPropertiesToIgnore { public string Name { get; set; } [Text(Ignore = true)] public string PropertyToIgnore { get; set; } [PropertyName("anotherPropertyToIgnore", Ignore = true)] public string AnotherPropertyToIgnore { get; set; } public string FluentMappingPropertyToIgnore { get; set; } [Ignore, JsonIgnore] public string JsonIgnoredProperty { get; set; } }
All of the properties except Name
have been ignored in the mapping
var connectionSettings = new ConnectionSettings(new InMemoryConnection()) .DisableDirectStreaming() .DefaultMappingFor<CompanyWithAttributesAndPropertiesToIgnore>(m => m .Ignore(p => p.FluentMappingPropertyToIgnore) ); var client = new ElasticClient(connectionSettings); var createIndexResponse = client.Indices.Create("myindex", c => c .Map<CompanyWithAttributesAndPropertiesToIgnore>(m => m .AutoMap() ) );
we’re using an in-memory connection, but in your application, you’ll want to use an |
|
we disable direct streaming here to capture the request and response bytes. In a production application, you would likely not call this as it adds overhead to each call. |
The JSON output for the mapping does not contain the ignored properties
{ "mappings": { "properties": { "name": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } } }
Ignoring inherited properties
editBy using the DefaultMappingFor<T>()
configuration for a POCO on the ConnectionSettings
, it is possible to
ignore inherited properties too
public class Parent { public int Id { get; set; } public string Description { get; set; } public string IgnoreMe { get; set; } } public class Child : Parent { } var connectionSettings = new ConnectionSettings(new InMemoryConnection()) .DisableDirectStreaming() .DefaultMappingFor<Child>(m => m .PropertyName(p => p.Description, "desc") .Ignore(p => p.IgnoreMe) ); var client = new ElasticClient(connectionSettings); var createIndexResponse = client.Indices.Create("myindex", c => c .Map<Child>(m => m .AutoMap() ) );
The property IgnoreMe
has been ignored for the child mapping
{ "mappings": { "properties": { "id": { "type": "integer" }, "desc": { "fields": { "keyword": { "ignore_above": 256, "type": "keyword" } }, "type": "text" } } } }
Overriding inherited properties
editDefaultMappingFor<T>()
configuration for a POCO on the ConnectionSettings
can also be
used to override inherited properties.
In the following example, the Id
property is shadowed in ParentWithStringId
as
a string
type, resulting in NEST’s automapping inferring the mapping as the default
text
with keyword
multi-field field datatype mapping for a string
type.
public class ParentWithStringId : Parent { public new string Id { get; set; } } var connectionSettings = new ConnectionSettings(new InMemoryConnection()) .DisableDirectStreaming() .DefaultMappingFor<ParentWithStringId>(m => m .Ignore(p => p.Description) .Ignore(p => p.IgnoreMe) ); var client = new ElasticClient(connectionSettings); var createIndexResponse = client.Indices.Create("myindex", c => c .Map<ParentWithStringId>(m => m .AutoMap() ) );
we’re using an in memory connection for this example. In your production application though, you’ll want to use an |
|
we disable direct streaming here to capture the request and response bytes. In your production application however, you’ll likely not want to do this, since it causes the request and response bytes to be buffered in memory. |
{ "mappings": { "properties": { "id": { "type": "text", "fields": { "keyword": { "ignore_above": 256, "type": "keyword" } } } } } }