- .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.
Index name inference
editIndex name inference
editMany endpoints within the Elasticsearch API expect to receive one or more index names as part of the request, in order to know what index/indices a request should operate on.
NEST has a number of ways in which the index name(s) can be specified
Default Index name on Connection Settings
editA default index name can be specified on ConnectionSettings
using .DefaultIndex()
.
This is the default index name to use when no other index name can be resolved for a request
var settings = new ConnectionSettings() .DefaultIndex("defaultindex"); var resolver = new IndexNameResolver(settings); var index = resolver.Resolve<Project>(); index.Should().Be("defaultindex");
Mapping an Index name for a .NET type
editA index name can be mapped for CLR types using .MapDefaultTypeIndices()
on ConnectionSettings
.
var settings = new ConnectionSettings() .MapDefaultTypeIndices(m => m .Add(typeof(Project), "projects") ); var resolver = new IndexNameResolver(settings); var index = resolver.Resolve<Project>(); index.Should().Be("projects");
.InferMappingFor<T>()
can also be used to specify the index name, as well as be used
to specify the type name and POCO property that should be used as the id for the document
var settings = new ConnectionSettings() .InferMappingFor<Project>(m => m .IndexName("projects") ); var resolver = new IndexNameResolver(settings); var index = resolver.Resolve<Project>(); index.Should().Be("projects");
An index name for a POCO provided using .MapDefaultTypeIndices()
or .InferMappingFor<T>()
will take precedence over
the default index name set on ConnectionSettings
. This way, the client can be configured with a default index to use if no
index is specified, and a specific index to use for different POCO types.
var settings = new ConnectionSettings() .DefaultIndex("defaultindex") .MapDefaultTypeIndices(m => m .Add(typeof(Project), "projects") ); var resolver = new IndexNameResolver(settings); var index = resolver.Resolve<Project>(); index.Should().Be("projects");
Explicitly specifying Index name on the request
editFor API calls that expect an index name, the index name can be explicitly provided on the request
var client = TestClient.Default; var response = client.Search<Project>(s => s.Index("some-other-index")); var requestUri = response.ApiCall.Uri; requestUri.Should().NotBeNull(); requestUri.LocalPath.Should().StartWith("/some-other-index/");
When an index name is provided on a request, it will take precedence over the default
index name and any index name specified for the POCO type using .MapDefaultTypeIndices()
or
.InferMappingFor<T>()
var client = new ElasticClient(new AlwaysInMemoryConnectionSettings() .DefaultIndex("defaultindex") .InferMappingFor<Project>(m => m .IndexName("projects") )); var response = client.Search<Project>(s => s.Index("some-other-index")); response.ApiCall.Uri.Should().NotBeNull(); response.ApiCall.Uri.LocalPath.Should().StartWith("/some-other-index/");
In summary, the order of precedence for determining the index name for a request is
- Index name specified on the request
-
Index name specified for the generic type parameter in the request using
.MapDefaultTypeIndices()
or.InferMappingFor<T>()
-
Default index name specified on
ConnectionSettings
On this page