Example #1
0
        /**== 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()
                );
        }
        [U] public void IndicesDebug()
        {
            Nest.Indices all          = Nest.Indices.All;
            Nest.Indices fromTypeName = Infer.Index <Project>();
            Nest.Indices fromType     = typeof(CommitActivity);
            Nest.Indices multiple     = Infer.Index("someindex").And <Project>();

            DebugFor(all).Should().Be("_all");
            DebugFor(fromTypeName).Should().Be($"Count: 1 [(1: IndexName for typeof: {nameof(Project)})]");
            DebugFor(fromType).Should().Be($"Count: 1 [(1: IndexName for typeof: {nameof(CommitActivity)})]");
            DebugFor(multiple).Should().Be($"Count: 2 [(1: someindex),(2: IndexName for typeof: {nameof(Project)})]");
        }
Example #3
0
        /**[[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))
                );
        }
Example #4
0
        [U] public async Task Urls()
        {
            var index = "index1,index2";

            Nest.Indices indices = index;
            await PUT($"/index1%2Cindex2/_settings")
            .Fluent(c => c.UpdateIndexSettings(indices, s => s))
            .Request(c => c.UpdateIndexSettings(new UpdateIndexSettingsRequest(index)))
            .FluentAsync(c => c.UpdateIndexSettingsAsync(indices, s => s))
            .RequestAsync(c => c.UpdateIndexSettingsAsync(new UpdateIndexSettingsRequest(index)))
            ;
            await PUT($"/_settings")
            .Fluent(c => c.UpdateIndexSettings(AllIndices, s => s))
            .Request(c => c.UpdateIndexSettings(new UpdateIndexSettingsRequest()))
            .FluentAsync(c => c.UpdateIndexSettingsAsync(AllIndices, s => s))
            .RequestAsync(c => c.UpdateIndexSettingsAsync(new UpdateIndexSettingsRequest()))
            ;
        }
Example #5
0
        public async Task Urls()
        {
            var index = "index1,index2";

            Nest.Indices indices = index;
            var          fields  = Field <Project>(p => p.Name).And("field");

            await GET($"/_mapping/field/name%2Cfield")
            .Request(c => c.Indices.GetFieldMapping(new GetFieldMappingRequest(fields)))
            .RequestAsync(c => c.Indices.GetFieldMappingAsync(new GetFieldMappingRequest(fields)))
            ;

            await GET($"/index1%2Cindex2/_mapping/field/name%2Cfield")
            .Fluent(c => c.Indices.GetFieldMapping <Project>(fields, g => g.Index(index)))
            .Request(c => c.Indices.GetFieldMapping(new GetFieldMappingRequest(indices, fields)))
            .FluentAsync(c => c.Indices.GetFieldMappingAsync <Project>(fields, g => g.Index(index)))
            .RequestAsync(c => c.Indices.GetFieldMappingAsync(new GetFieldMappingRequest(indices, fields)))
            ;
        }
        [I] public async Task GetTransformResponse() => await Assert <GetTransformResponse>(GetTransformStep, (v, r) =>
        {
            r.ShouldBeValid();
            r.Count.Should().Be(1);
            var transform = r.Transforms.First();

            transform.Id.Should().Be(v);
            transform.Description.Should().Be(v);
            transform.Frequency.Should().Be(new Time(1, TimeUnit.Second));
            transform.Destination.Should().NotBeNull();
            transform.Destination.Index.Should().Be($"transform-{v}");

            Nest.Indices indices = "project";
            transform.Source.Index.Should().Be(indices);
            ((IQueryContainer)transform.Source.Query).MatchAll.Should().NotBeNull();

            transform.Pivot.Should().NotBeNull();
            transform.Pivot.GroupBy.Should().ContainKey("weekStartedOn");
            transform.Pivot.Aggregations["averageCommits"].Should().NotBeNull();
            transform.Pivot.Aggregations["sumIntoMaster"].Should().NotBeNull();
        });
        [U] public async Task Urls()
        {
            var index = "index1,index2";

            Nest.Indices indices = index;
            var          name    = "name";
            Name         n       = name;

            await GET($"/index1%2Cindex2/_settings/{name}")
            .Fluent(c => c.Indices.GetSettings(index, m => m.Name(name)))
            .Request(c => c.Indices.GetSettings(new GetIndexSettingsRequest(index, name)))
            .FluentAsync(c => c.Indices.GetSettingsAsync(index, m => m.Name(name)))
            .RequestAsync(c => c.Indices.GetSettingsAsync(new GetIndexSettingsRequest(index, name)))
            ;

            await GET($"/index1%2Cindex2/_settings")
            .Fluent(c => c.Indices.GetSettings(index))
            .Request(c => c.Indices.GetSettings(new GetIndexSettingsRequest(indices)))
            .FluentAsync(c => c.Indices.GetSettingsAsync(index))
            .RequestAsync(c => c.Indices.GetSettingsAsync(new GetIndexSettingsRequest(indices)))
            ;

            await GET($"/_settings/{name}")
            .Fluent(c => c.Indices.GetSettings(null, m => m.Name(name)))
            .Request(c => c.Indices.GetSettings(new GetIndexSettingsRequest(n)))
            .FluentAsync(c => c.Indices.GetSettingsAsync(null, m => m.Name(name)))
            .RequestAsync(c => c.Indices.GetSettingsAsync(new GetIndexSettingsRequest(n)))
            ;
            await GET($"/_all/_settings")
            .Fluent(c => c.Indices.GetSettings(AllIndices))
            .Request(c => c.Indices.GetSettings(new GetIndexSettingsRequest(AllIndices)))
            .FluentAsync(c => c.Indices.GetSettingsAsync(AllIndices))
            .RequestAsync(c => c.Indices.GetSettingsAsync(new GetIndexSettingsRequest(AllIndices)))
            ;

            await GET($"/_settings")
            .Request(c => c.Indices.GetSettings(new GetIndexSettingsRequest()))
            .RequestAsync(c => c.Indices.GetSettingsAsync(new GetIndexSettingsRequest()))
            ;
        }
Example #8
0
        //hide
        [U] public void EqualsValidation()
        {
            var clusterIndex = (IndexName)"cluster_one:p";
            var index        = (IndexName)"p";

            Index <Project>("cluster_one").Should().NotBe(Index <Project>("cluster_two"));

            clusterIndex.Should().NotBe(index);
            clusterIndex.Should().Be("cluster_one:p");
            clusterIndex.Should().Be((IndexName)"cluster_one:p");

            Index <Project>().Should().Be(Index <Project>());
            Index <Project>().Should().NotBe(Index <Project>("cluster_two"));
            Index <Project>("cluster_one").Should().NotBe("cluster_one:project");
            Index <Project>().Should().NotBe(Index <Developer>());
            Index <Project>("cluster_one").Should().NotBe(Index <Developer>("cluster_one"));

            Nest.Indices indices1 = "foo,bar";
            Nest.Indices indices2 = "bar,foo";
            indices1.Should().Be(indices2);
            (indices1 == indices2).Should().BeTrue();
        }
Example #9
0
        public async Task Urls()
        {
            var index = "index1,index2";

            Nest.Indices indices = index;
            var          types   = Type <Project>().And <CommitActivity>();
            var          fields  = Field <Project>(p => p.Name).And("field");

            await GET($"/_mapping/field/name,field")
            .Fluent(c => c.GetFieldMapping <Project>(fields))
            .Request(c => c.GetFieldMapping(new GetFieldMappingRequest(fields)))
            .FluentAsync(c => c.GetFieldMappingAsync <Project>(fields))
            .RequestAsync(c => c.GetFieldMappingAsync(new GetFieldMappingRequest(fields)))
            ;

            await GET($"/{index}/_mapping/field/name,field")
            .Fluent(c => c.GetFieldMapping <Project>(fields, g => g.Index(index)))
            .Request(c => c.GetFieldMapping(new GetFieldMappingRequest(indices, fields)))
            .FluentAsync(c => c.GetFieldMappingAsync <Project>(fields, g => g.Index(index)))
            .RequestAsync(c => c.GetFieldMappingAsync(new GetFieldMappingRequest(indices, fields)))
            ;

            await GET($"/_mapping/project,commits/field/name,field")
            .Fluent(c => c.GetFieldMapping <Project>(fields, g => g.Type(types)))
            .Request(c => c.GetFieldMapping(new GetFieldMappingRequest(types, fields)))
            .FluentAsync(c => c.GetFieldMappingAsync <Project>(fields, g => g.Type(types)))
            .RequestAsync(c => c.GetFieldMappingAsync(new GetFieldMappingRequest(types, fields)))
            ;

            await GET($"/{index}/_mapping/project,commits/field/name,field")
            .Fluent(c => c.GetFieldMapping <Project>(fields, g => g.Index(indices).Type(types)))
            .Request(c => c.GetFieldMapping(new GetFieldMappingRequest(indices, types, fields)))
            .FluentAsync(c => c.GetFieldMappingAsync <Project>(fields, g => g.Index(indices).Type(types)))
            .RequestAsync(c => c.GetFieldMappingAsync(new GetFieldMappingRequest(indices, types, fields)))
            ;
        }
 ///<summary>A comma-separated list of index names; use the special string `_all` or Indices.All to perform the operation on all indices</summary>
 public ClusterStateDescriptor Index(Indices index) => Assign(index, (a, v) => a.RouteValues.Optional("index", v));
 public static ForceMergeResponse ForceMerge(this IElasticClient client, Indices indices,
                                             Func <ForceMergeDescriptor, IForceMergeRequest> selector = null
                                             )
 => client.Indices.ForceMerge(indices, selector);
 /// <inheritdoc />
 public OpenIndexResponse OpenIndex(Indices indices, Func <OpenIndexDescriptor, IOpenIndexRequest> selector = null) =>
 OpenIndex(selector.InvokeOrDefault(new OpenIndexDescriptor(indices)));
Example #13
0
 /// <inheritdoc cref="IBulkAllRequest{T}.RefreshIndices" />
 public BulkAllDescriptor <T> RefreshIndices(Indices indicesToRefresh) => Assign(indicesToRefresh, (a, v) => a.RefreshIndices = v);
 public static Task <ForceMergeResponse> ForceMergeAsync(this IElasticClient client, Indices indices,
                                                         Func <ForceMergeDescriptor, IForceMergeRequest> selector = null,
                                                         CancellationToken ct = default
                                                         )
 => client.Indices.ForceMergeAsync(indices, selector, ct);
Example #15
0
 /// <inheritdoc cref="IRestoreRequest.Indices" />
 public CloneSnapshotDescriptor Indices(Indices indices) => Assign(indices, (a, v) => a.Indices = v);
 /// <inheritdoc />
 public Task <IRecoveryStatusResponse> RecoveryStatusAsync(Indices indices,
                                                           Func <RecoveryStatusDescriptor, IRecoveryStatusRequest> selector = null, CancellationToken cancellationToken = default(CancellationToken)
                                                           ) =>
 RecoveryStatusAsync(selector.InvokeOrDefault(new RecoveryStatusDescriptor().Index(indices)), cancellationToken);
 /// <inheritdoc />
 public Task <OpenIndexResponse> OpenIndexAsync(
     Indices indices,
     Func <OpenIndexDescriptor, IOpenIndexRequest> selector = null,
     CancellationToken ct = default
     ) => OpenIndexAsync(selector.InvokeOrDefault(new OpenIndexDescriptor(indices)), ct);
 /// <inheritdoc />
 public IRecoveryStatusResponse RecoveryStatus(Indices indices, Func <RecoveryStatusDescriptor, IRecoveryStatusRequest> selector = null) =>
 RecoveryStatus(selector.InvokeOrDefault(new RecoveryStatusDescriptor().Index(indices)));
Example #19
0
 public static Task <UpdateIndexSettingsResponse> UpdateIndexSettingsAsync(this IElasticClient client,
                                                                           Indices indices,
                                                                           Func <UpdateIndexSettingsDescriptor, IUpdateIndexSettingsRequest> selector,
                                                                           CancellationToken ct = default
                                                                           )
 => client.Indices.UpdateSettingsAsync(indices, selector, ct);
Example #20
0
 /// <inheritdoc />
 public UpdateDatafeedDescriptor <T> Indices(Indices indices) => Assign(a => a.Indices = indices);
Example #21
0
 /// <inheritdoc/>
 public Task <IRecoveryStatusResponse> RecoveryStatusAsync(Indices indices, Func <RecoveryStatusDescriptor, IRecoveryStatusRequest> selector = null) =>
 this.RecoveryStatusAsync(selector.InvokeOrDefault(new RecoveryStatusDescriptor().Index(indices)));
 ///<summary>/_cluster/state/{metric}/{index}</summary>
 ///<param name = "metric">Optional, accepts null</param>
 ///<param name = "index">Optional, accepts null</param>
 public ClusterStateDescriptor(Metrics metric, Indices index) : base(r => r.Optional("metric", metric).Optional("index", index))
 {
 }
Example #23
0
 /// <inheritdoc/>
 public Task <IIndicesResponse> DeleteIndexAsync(Indices indices, Func <DeleteIndexDescriptor, IDeleteIndexRequest> selector = null) =>
 this.DeleteIndexAsync(selector.InvokeOrDefault(new DeleteIndexDescriptor(indices)));
 ///<summary>/_cluster/health/{index}</summary>
 ///<param name = "index">Optional, accepts null</param>
 public ClusterHealthDescriptor(Indices index) : base(r => r.Optional("index", index))
 {
 }
 /// <inheritdoc/>
 public Task <IAcknowledgedResponse> DeleteWarmerAsync(Indices indices, Names names, Func <DeleteWarmerDescriptor, IDeleteWarmerRequest> selector = null) =>
 this.DeleteWarmerAsync(selector.InvokeOrDefault(new DeleteWarmerDescriptor(indices, names)));
Example #26
0
 public static UpdateIndexSettingsResponse UpdateIndexSettings(this IElasticClient client, Indices indices,
                                                               Func <UpdateIndexSettingsDescriptor, IUpdateIndexSettingsRequest> selector
                                                               )
 => client.Indices.UpdateSettings(indices, selector);
 /// <inheritdoc cref="AliasRemoveOperation.Indices"/>
 public AliasRemoveDescriptor Indices(Indices indices)
 {
     Self.Remove.Indices = indices;
     return(this);
 }
Example #28
0
 public string GetString(IConnectionConfigurationValues settings) => ((IUrlParameter)(Indices)(Indices.Index(this))).GetString(settings);
Example #29
0
 /// <inheritdoc/>
 public Task <IShardsOperationResponse> ClearCacheAsync(Indices indices, Func <ClearCacheDescriptor, IClearCacheRequest> selector = null) => this.Dispatcher.DispatchAsync <IClearCacheRequest, ClearCacheRequestParameters, ShardsOperationResponse, IShardsOperationResponse>(
     selector.InvokeOrDefault(new ClearCacheDescriptor().Index(indices)),
     (p, d) => this.LowLevelDispatch.IndicesClearCacheDispatchAsync <ShardsOperationResponse>(p)
     );