/**== Indices paths * * Some APIs in Elasticsearch take one or many index name or a special `_all` marker to send the request to all the indices * In nest this is encoded using `Indices`. * *=== Implicit Conversion * Several types implicitly convert to `Indices` */ [U] public void ImplicitConversionFromString() { Nest.Indices singleIndexFromString = "name"; Nest.Indices multipleIndicesFromString = "name1, name2"; Nest.Indices allFromString = "_all"; Nest.Indices allWithOthersFromString = "_all, name2"; 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() ); }
/**[[indices-paths]] * === Indices paths * * Some 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 * * To make working with `Indices` easier, several types implicitly convert to it: * * - `string` * - comma separated `string` * - `string` array * - a CLR type, <<index-name-inference, 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 */ [U] public void ImplicitConversions() { Nest.Indices singleIndexFromString = "name"; Nest.Indices multipleIndicesFromString = "name1, name2"; Nest.Indices multipleIndicesFromStringArray = new [] { "name1", "name2" }; Nest.Indices allFromString = "_all"; Nest.Indices allWithOthersFromString = "_all, name2"; //<1> `_all` will override any specific index names here Nest.Indices singleIndexFromType = typeof(Project); //<2> The `Project` type has been mapped to a specific index name using <<index-name-type-mapping,`.DefaultMappingFor<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)) ); }