- .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
Indices paths
editIndices paths
editSome APIs in Elasticsearch take an index name, a collection of index names,
or the special _all
marker (used to specify all indices), in the URI path of the request, to specify the indices that
the request should execute against.
In NEST, these index names can be specified using the Indices
type.
Implicit Conversion
editTo make working with Indices
easier, several types implicitly convert to it:
-
string
-
comma separated
string
-
string
array -
a CLR type, where a default index name or index name for the type has been specified on
ConnectionSettings
-
IndexName
-
IndexName
array
Here are some examples of how implicit conversions can be used to specify index names
Nest.Indices singleIndexFromString = "name"; Nest.Indices multipleIndicesFromString = "name1, name2"; Nest.Indices multipleIndicesFromStringArray = new [] { "name1", "name2" }; Nest.Indices allFromString = "_all"; Nest.Indices allWithOthersFromString = "_all, name2"; Nest.Indices singleIndexFromType = typeof(Project); Nest.Indices singleIndexFromIndexName = IndexName.From<Project>(); singleIndexFromString.Match( all => all.Should().BeNull(), many => many.Indices.Should().HaveCount(1).And.Contain("name") ); multipleIndicesFromString.Match( all => all.Should().BeNull(), many => many.Indices.Should().HaveCount(2).And.Contain("name2") ); allFromString.Match( all => all.Should().NotBeNull(), many => many.Indices.Should().BeNull() ); allWithOthersFromString.Match( all => all.Should().NotBeNull(), many => many.Indices.Should().BeNull() ); multipleIndicesFromStringArray.Match( all => all.Should().BeNull(), many => many.Indices.Should().HaveCount(2).And.Contain("name2") ); singleIndexFromType.Match( all => all.Should().BeNull(), many => many.Indices.Should().HaveCount(1).And.Contain(typeof(Project)) ); singleIndexFromIndexName.Match( all => all.Should().BeNull(), many => many.Indices.Should().HaveCount(1).And.Contain(typeof(Project)) );
|
|
The |
Using Nest.Indices methods
editTo make creating IndexName
or Indices
instances easier, Nest.Indices
also contains several static methods
that can be used to construct them.
Single index
editA single index can be specified using a CLR type or a string, and the .Index()
method.
This example uses the static import using static Nest.Indices;
in the using directives to shorthand Nest.Indices.Index()
to simply Index()
. Be sure to include this static import if copying any of these examples.
var client = TestClient.Default; var singleString = Index("name1"); var singleTyped = Index<Project>(); ISearchRequest singleStringRequest = new SearchDescriptor<Project>().Index(singleString); ISearchRequest singleTypedRequest = new SearchDescriptor<Project>().Index(singleTyped); ((IUrlParameter)singleStringRequest.Index).GetString(this.Client.ConnectionSettings).Should().Be("name1"); ((IUrlParameter)singleTypedRequest.Index).GetString(this.Client.ConnectionSettings).Should().Be("project"); var invalidSingleString = Index("name1, name2");
Multiple indices
editSimilarly to a single index, multiple indices can be specified using multiple CLR types or multiple strings
var manyStrings = Index("name1", "name2"); var manyTypes = Index<Project>().And<Developer>(); var client = TestClient.Default; ISearchRequest manyStringRequest = new SearchDescriptor<Project>().Index(manyStrings); ISearchRequest manyTypedRequest = new SearchDescriptor<Project>().Index(manyTypes); ((IUrlParameter)manyStringRequest.Index).GetString(this.Client.ConnectionSettings).Should().Be("name1,name2"); ((IUrlParameter)manyTypedRequest.Index).GetString(this.Client.ConnectionSettings).Should().Be("project,devs"); manyStringRequest = new SearchDescriptor<Project>().Index(new[] { "name1", "name2" }); ((IUrlParameter)manyStringRequest.Index).GetString(this.Client.ConnectionSettings).Should().Be("name1,name2");
specifying multiple indices using strings |
|
specifying multiple indices using types |
|
The index names here come from the Connection Settings passed to |
All Indices
editElasticsearch allows searching across multiple indices using the special _all
marker.
NEST exposes the _all
marker with Indices.All
and Indices.AllIndices
. Why expose it in two ways, you ask?
Well, you may be using both Nest.Indices
and Nest.Types
in the same file and you may also be using C#6
static imports too; in this scenario, the All
property becomes ambiguous between Indices.All
and Types.All
, so the
_all
marker for indices is exposed as Indices.AllIndices
, to alleviate this ambiguity
var indicesAll = All; var allIndices = AllIndices; ISearchRequest indicesAllRequest = new SearchDescriptor<Project>().Index(indicesAll); ISearchRequest allIndicesRequest = new SearchDescriptor<Project>().Index(allIndices); ((IUrlParameter)indicesAllRequest.Index).GetString(this.Client.ConnectionSettings).Should().Be("_all"); ((IUrlParameter)allIndicesRequest.Index).GetString(this.Client.ConnectionSettings).Should().Be("_all");