Exemplo n.º 1
0
        public IBulkResponse IndexSearchResults(ISearchResponse <T> searchResult, IObserver <IReindexResponse <T> > observer, string toIndex, int page)
        {
            if (!searchResult.IsValid)
            {
                throw new ReindexException(searchResult.ConnectionStatus, "reindex failed on scroll #" + page);
            }

            var bb = new BulkDescriptor();

            foreach (var d in searchResult.Hits)
            {
                IHit <T> d1 = d;
                bb.Index <T>(bi => bi.Object(d1.Source).Type(d1.Type).Index(toIndex).Id(d.Id));
            }

            var indexResult = this.CurrentClient.Bulk(b => bb);

            if (!indexResult.IsValid)
            {
                throw new ReindexException(indexResult.ConnectionStatus, "reindex failed when indexing page " + page);
            }

            observer.OnNext(new ReindexResponse <T>()
            {
                BulkResponse   = indexResult,
                SearchResponse = searchResult,
                Scroll         = page
            });
            return(indexResult);
        }
Exemplo n.º 2
0
        //used by IndexMany and DeleteMany
        private string GenerateBulkCommand <T>(IEnumerable <T> @objects, string index, string typeName, string command) where T : class
        {
            objects.ThrowIfEmpty("objects");

            var b = new BulkDescriptor();

            b.FixedPath(index, typeName);
            foreach (var @object in @objects)
            {
                var o = @object;
                if (command == "index")
                {
                    b.Index <T>(bb => bb.Object(o));
                }
                else if (command == "delete")
                {
                    b.Delete <T>(bb => bb.Object(o));
                }
            }

            string json, path;

            this.GenerateBulkPathAndJson(b, out json, out path);
            return(json);
        }
Exemplo n.º 3
0
        public IBulkResponse IndexSearchResults(ISearchResponse <T> searchResult, IObserver <IReindexResponse <T> > observer, IndexName toIndex, int page)
        {
            if (!searchResult.IsValid)
            {
                throw new ElasticsearchClientException(PipelineFailure.BadResponse, $"Indexing failed on scroll #{page}.", searchResult.ApiCall);
            }

            var bb = new BulkDescriptor();

            foreach (var d in searchResult.Hits)
            {
                IHit <T> d1 = d;
                bb.Index <T>(bi => bi.Document(d1.Source).Type(d1.Type).Index(toIndex).Id(d.Id));
            }

            var indexResult = this._client.Bulk(b => bb);

            if (!indexResult.IsValid)
            {
                throw new ElasticsearchClientException(PipelineFailure.BadResponse, $"Failed indexing page {page}.", indexResult.ApiCall);
            }

            observer.OnNext(new ReindexResponse <T>()
            {
                BulkResponse   = indexResult,
                SearchResponse = searchResult,
                Scroll         = page
            });
            return(indexResult);
        }
Exemplo n.º 4
0
        /// <inheritdoc />
        public IBulkResponse IndexMany <T>(IEnumerable <T> @objects, string index = null, string type = null) where T : class
        {
            @objects.ThrowIfEmpty("objects");
            var bulk = new BulkDescriptor().FixedPath(index, type);

            foreach (var o in @objects)
            {
                var o1 = o;
                bulk.Index <T>(b => b.Object(o1));
            }
            return(Bulk(b => bulk));
        }
Exemplo n.º 5
0
        //used by IndexMany and DeleteMany
        private string GenerateBulkCommand <T>(IEnumerable <BulkParameters <T> > @objects, string index, string typeName, string command) where T : class
        {
            objects.ThrowIfEmpty("objects");


            var b = new BulkDescriptor();

            b.FixedPath(index, typeName);
            foreach (var @object in @objects)
            {
                var o = @object;
                if (command == "index")
                {
                    b.Index <T>(bb => bb
                                .Object(o.Document)
                                .Id(o.Id)
                                .Parent(o.Parent)
                                .Percolate(o.Percolate)
                                .Routing(o.Routing)
                                .Timestamp(o.Timestamp)
                                .Ttl(o.Ttl)
                                .Version(o.Version)
                                .VersionType(o.VersionType));
                }
                else if (command == "delete")
                {
                    b.Delete <T>(bb => bb
                                 .Object(o.Document)
                                 .Parent(o.Parent)
                                 .Routing(o.Routing)
                                 .Timestamp(o.Timestamp)
                                 .Ttl(o.Ttl)
                                 .Version(o.Version)
                                 .VersionType(o.VersionType));
                }
            }

            string json, path;

            this.GenerateBulkPathAndJson(b, out json, out path);
            return(json);
        }