private static BulkRequest CreateDeleteBulkRequest <T>(IEnumerable <T> objects, IndexName index) where T : class
        {
            // ReSharper disable once PossibleMultipleEnumeration
            objects.ThrowIfEmpty(nameof(objects));
            var bulkRequest = new BulkRequest(index);
            // ReSharper disable once PossibleMultipleEnumeration
            var deletes = objects
                          .Select(o => new BulkDeleteOperation <T>(o))
                          .Cast <IBulkOperation>()
                          .ToList();

            bulkRequest.Operations = new BulkOperationsCollection <IBulkOperation>(deletes);

            return(bulkRequest);
        }
        private static BulkRequest CreateIndexBulkRequest <T>(IEnumerable <T> objects, IndexName index) where T : class
        {
            @objects.ThrowIfEmpty(nameof(objects));
            var bulkRequest = new BulkRequest(index);
            var indexOps    = @objects
                              .Select(o => new BulkIndexOperation <T>(o))
                              .Cast <IBulkOperation>()
                              .ToList();

            bulkRequest.Operations = new BulkOperationsCollection <IBulkOperation>(indexOps);
            return(bulkRequest);
        }
 /// <inheritdoc />
 public CreateIndexResponse CreateIndex(IndexName index, Func <CreateIndexDescriptor, ICreateIndexRequest> selector = null) =>
 CreateIndex(selector.InvokeOrDefault(new CreateIndexDescriptor(index)));
 /// <summary>
 /// Manually set the index, default to the default index or the fixed index set on the bulk operation
 /// </summary>
 public TDescriptor Index(IndexName index) => Assign(a => a.Index = index);
        /// <summary>
        /// Shortcut into the Bulk call that indexes the specified objects
        /// <para> </para>
        /// https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
        /// </summary>
        /// <param name="client"></param>
        /// <typeparam name="T">The type used to infer the default index and typename</typeparam>
        /// <param name="objects">List of objects to index, Id will be inferred (Id property or IdProperty attribute on type)</param>
        /// <param name="index">Override the inferred indexname for T</param>
        /// <param name="type">Override the inferred typename for T</param>
        public static BulkResponse IndexMany <T>(this IElasticClient client, IEnumerable <T> @objects, IndexName index = null)
            where T : class
        {
            var bulkRequest = CreateIndexBulkRequest(objects, index);

            return(client.Bulk(bulkRequest));
        }
Esempio n. 6
0
 public ShrinkIndexResponse ShrinkIndex(
     IndexName source,
     IndexName target,
     Func <ShrinkIndexDescriptor, IShrinkIndexRequest> selector = null
     ) => ShrinkIndex(selector.InvokeOrDefault(new ShrinkIndexDescriptor(source, target)));
 ///<summary>/{index}/_migration/deprecations</summary>
 ///<param name = "index">Optional, accepts null</param>
 public DeprecationInfoDescriptor(IndexName index) : base(r => r.Optional("index", index))
 {
 }
Esempio n. 8
0
        private static IReadOnlyDictionary <string, AliasDefinition> AliasesPointingToIndex(IndexName index, GetAliasResponse response)
        {
            if (!response.IsValid || !response.Indices.HasAny())
            {
                return(EmptyReadOnly <string, AliasDefinition> .Dictionary);
            }

            return(response.Indices[index].Aliases);
        }
Esempio n. 9
0
 public DocumentPath <T> Index(IndexName index)
 {
     Self.Index = index;
     return(this);
 }
Esempio n. 10
0
        /// <summary>
        /// Returns a dictionary of aliases that point to the specified index, simplified version of
        /// <see cref="IElasticClient.GetAlias(IGetAliasRequest)" />..
        /// </summary>
        /// <param name="index">The index name we want to know aliases of</param>
        public static IReadOnlyDictionary <string, AliasDefinition> GetAliasesPointingToIndex(this IElasticClient client, IndexName index)
        {
            var response = client.GetAlias(a => a.Index(index).RequestConfiguration(r => r.ThrowExceptions()));

            return(AliasesPointingToIndex(index, response));
        }
Esempio n. 11
0
        /// <summary>
        /// Returns a dictionary of aliases that point to the specified index, simplified version of
        /// <see cref="IElasticClient.GetAlias(IGetAliasRequest)" />.
        /// </summary>
        /// <param name="index">The index name we want to know aliases of</param>
        public static async Task <IReadOnlyDictionary <string, AliasDefinition> > GetAliasesPointingToIndexAsync(this IElasticClient client,
                                                                                                                 IndexName index
                                                                                                                 )
        {
            var response = await client.GetAliasAsync(a => a.Index(index).RequestConfiguration(r => r.ThrowExceptions())).ConfigureAwait(false);

            return(AliasesPointingToIndex(index, response));
        }
 /// <inheritdoc />
 public ValidateJobDescriptor <TDocument> ResultsIndexName(IndexName indexName) => Assign(indexName, (a, v) => a.ResultsIndexName = v);
 /// <inheritdoc cref="IPainlessContextSetup.Index" />
 public PainlessContextSetupDescriptor Index(IndexName index) => Assign(a => a.Index = index);
 /// <inheritdoc cref="IRestoreRequest.Indices"/>
 public RestoreDescriptor Index(IndexName index) => this.Indices(index);
Esempio n. 15
0
 /// <inheritdoc cref="UnfollowIndex(IndexName, System.Func{Nest.UnfollowIndexDescriptor,Nest.IUnfollowIndexRequest})" />
 public UnfollowIndexResponse UnfollowIndex(IndexName index, Func <UnfollowIndexDescriptor, IUnfollowIndexRequest> selector = null) =>
 UnfollowIndex(selector.InvokeOrDefault(new UnfollowIndexDescriptor(index)));
Esempio n. 16
0
 internal static bool IsNullOrEmpty(this IndexName value) => value == null || value.GetHashCode() == 0;
Esempio n. 17
0
 /// <inheritdoc cref="UnfollowIndex(IndexName, System.Func{Nest.UnfollowIndexDescriptor,Nest.IUnfollowIndexRequest})" />
 public Task <UnfollowIndexResponse> UnfollowIndexAsync(
     IndexName index,
     Func <UnfollowIndexDescriptor, IUnfollowIndexRequest> selector = null,
     CancellationToken ct = default
     ) => UnfollowIndexAsync(selector.InvokeOrDefault(new UnfollowIndexDescriptor(index)), ct);
 public static Task <GetRollupIndexCapabilitiesResponse> GetRollupIndexCapabilitiesAsync(this IElasticClient client,
                                                                                         IndexName index,
                                                                                         Func <GetRollupIndexCapabilitiesDescriptor, IGetRollupIndexCapabilitiesRequest> selector = null,
                                                                                         CancellationToken ct = default
                                                                                         )
 => client.Rollup.GetIndexCapabilitiesAsync(index, selector, ct);
Esempio n. 19
0
 public Task <ShrinkIndexResponse> ShrinkIndexAsync(
     IndexName source,
     IndexName target,
     Func <ShrinkIndexDescriptor, IShrinkIndexRequest> selector = null,
     CancellationToken cancellationToken = default
     ) => ShrinkIndexAsync(selector.InvokeOrDefault(new ShrinkIndexDescriptor(source, target)));
 public static GetRollupIndexCapabilitiesResponse GetRollupIndexCapabilities(this IElasticClient client,
                                                                             IndexName index,
                                                                             Func <GetRollupIndexCapabilitiesDescriptor, IGetRollupIndexCapabilitiesRequest> selector = null
                                                                             )
 => client.Rollup.GetIndexCapabilities(index, selector);
 ///<summary>Index pattern</summary>
 public DeprecationInfoDescriptor Index(IndexName index) => Assign(index, (a, v) => a.RouteValues.Optional("index", v));
 /// <inheritdoc />
 public ValidateJobDescriptor <T> ResultsIndexName(IndexName indexName) => Assign(a => a.ResultsIndexName = indexName);
Esempio n. 23
0
 public FieldLookupDescriptor <T> Index(IndexName index) => Assign(a => a.Index = index);
Esempio n. 24
0
 public string IndexName(IndexName index) => IndexNameResolver.Resolve(index);
        /// <summary>
        /// Shortcut into the Bulk call that indexes the specified objects
        /// <para> </para>
        /// https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
        /// </summary>
        /// <param name="client"></param>
        /// <typeparam name="T">The type used to infer the default index and typename</typeparam>
        /// <param name="objects">List of objects to index, Id will be inferred (Id property or IdProperty attribute on type)</param>
        /// <param name="index">Override the inferred indexname for T</param>
        /// <param name="type">Override the inferred typename for T</param>
        public static Task <BulkResponse> IndexManyAsync <T>(this IElasticClient client, IEnumerable <T> objects, IndexName index = null,
                                                             CancellationToken cancellationToken = default
                                                             )
            where T : class
        {
            var bulkRequest = CreateIndexBulkRequest(objects, index);

            return(client.BulkAsync(bulkRequest, cancellationToken));
        }
Esempio n. 26
0
 public IndexActionDescriptor Index(IndexName index) => Assign(index, (a, v) => a.Index = v);
Esempio n. 27
0
 ///<summary>/{index}/_ccr/follow</summary>
 ///<param name = "index">this parameter is required</param>
 public CreateFollowIndexRequest(IndexName index) : base(r => r.Required("index", index))
 {
 }
Esempio n. 28
0
 public AliasRemoveIndexDescriptor Index(IndexName index)
 {
     Self.RemoveIndex.Index = index;
     return(this);
 }
 /// <inheritdoc />
 public Task <CreateIndexResponse> CreateIndexAsync(
     IndexName index,
     Func <CreateIndexDescriptor, ICreateIndexRequest> selector = null,
     CancellationToken cancellationToken = default
     ) => CreateIndexAsync(selector.InvokeOrDefault(new CreateIndexDescriptor(index)));
Esempio n. 30
0
 /// <inheritdoc/>
 public Task <IIndicesOperationResponse> CreateIndexAsync(IndexName index, Func <CreateIndexDescriptor, ICreateIndexRequest> selector = null) =>
 this.CreateIndexAsync(selector.InvokeOrDefault(new CreateIndexDescriptor(index)));