- .NET Clients: other versions:
- Introduction
- 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
- Numeric Range Query Usage
- Term Range Query Usage
- Regexp Query Usage
- Term Query Usage
- Terms List Query Usage
- Terms Lookup Query Usage
- Terms Query Usage
- Type Query Usage
- Wildcard Query Usage
- Compound queries
- Joining queries
- Geo queries
- Geo Bounding Box Query Usage
- Geo Distance Query Usage
- Geo Distance Range Query Usage
- Geo Hash Cell Query Usage
- Geo Polygon Query Usage
- Geo Shape Circle Query Usage
- Geo Shape Envelope Query Usage
- Geo Shape Geometry Collection Query Usage
- Geo Shape Indexed Shape Query Usage
- Geo Shape Line String Query Usage
- Geo Shape Multi Line String Query Usage
- Geo Shape Multi Point Query Usage
- Geo Shape Multi Polygon Query Usage
- Geo Shape Point Query Usage
- Geo Shape Polygon Query Usage
- Specialized queries
- Span queries
- NEST specific queries
- Aggregations
- Metric Aggregations
- Average Aggregation Usage
- Cardinality Aggregation Usage
- Extended Stats Aggregation Usage
- Geo Bounds Aggregation Usage
- Geo Centroid Aggregation Usage
- Max Aggregation Usage
- Min Aggregation Usage
- Percentile Ranks Aggregation Usage
- Percentiles Aggregation Usage
- Scripted Metric Aggregation Usage
- Stats Aggregation Usage
- Sum Aggregation Usage
- Top Hits Aggregation Usage
- Value Count Aggregation Usage
- Bucket Aggregations
- Adjacency Matrix Usage
- Children Aggregation Usage
- Date Histogram Aggregation Usage
- Date Range Aggregation Usage
- Filter Aggregation Usage
- Filters Aggregation Usage
- Geo Distance Aggregation Usage
- Geo Hash Grid Aggregation Usage
- Global Aggregation Usage
- Histogram Aggregation Usage
- Ip Range Aggregation Usage
- Missing Aggregation Usage
- Nested Aggregation Usage
- Range Aggregation Usage
- Reverse Nested Aggregation Usage
- Sampler Aggregation Usage
- Significant Terms Aggregation Usage
- Terms Aggregation Usage
- Pipeline Aggregations
- Average Bucket Aggregation Usage
- Bucket Script Aggregation Usage
- Bucket Selector 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
- Percentiles Bucket Aggregation Usage
- Serial Differencing Aggregation Usage
- Stats Bucket Aggregation Usage
- Sum Bucket Aggregation Usage
- Matrix Aggregations
- Metric Aggregations
WARNING: Version 5.x has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
Ignoring properties
editIgnoring properties
editProperties on a POCO can be ignored for mapping purposes in a few ways:
-
Using the
Ignore
property on a derivedElasticsearchPropertyAttribute
type applied to the property that should be ignored on the POCO -
Using the
.InferMappingFor<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. In the case of the defaultJsonNetSerializer
, this is the Json.NETJsonIgnoreAttribute
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 JsonIgnoredProperty
[ElasticsearchType(Name = "company")] public class CompanyWithAttributesAndPropertiesToIgnore { public string Name { get; set; } [Text(Ignore = true)] public string PropertyToIgnore { get; set; } public string AnotherPropertyToIgnore { get; set; } [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() .InferMappingFor<CompanyWithAttributesAndPropertiesToIgnore>(m => m .Ignore(p => p.AnotherPropertyToIgnore) ); var client = new ElasticClient(connectionSettings); var createIndexResponse = client.CreateIndex("myindex", c => c .Mappings(ms => ms .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 your application however, you’ll like not want to do this in production. |
The JSON output for the mapping does not contain the ignored properties
{ "mappings": { "company": { "properties": { "name": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } } } }
Ignoring inherited properties
editBy using the infer mapping 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() .InferMappingFor<Child>(m => m .Rename(p => p.Description, "desc") .Ignore(p => p.IgnoreMe) ); var client = new ElasticClient(connectionSettings); var createIndexResponse = client.CreateIndex("myindex", c => c .Mappings(ms => ms .Map<Child>(m => m .AutoMap() ) ) );
The property IgnoreMe
has been ignored for the child mapping
{ "mappings": { "child": { "properties": { "id": { "type": "integer" }, "desc": { "fields": { "keyword": { "ignore_above": 256, "type": "keyword" } }, "type": "text" } } } } }
On this page