예제 #1
0
        private IEnumerable <Dotace> YieldAll(QueryContainer query,
                                              string scrollTimeout = "2m",
                                              int scrollSize       = 300)
        {
            ISearchResponse <Dotace> initialResponse = null;

            if (query is null)
            {
                initialResponse = _esClient.Search <Dotace>(scr => scr
                                                            .From(0)
                                                            .Take(scrollSize)
                                                            .MatchAll()
                                                            .Scroll(scrollTimeout));
            }
            else
            {
                initialResponse = _esClient.Search <Dotace>(scr => scr
                                                            .From(0)
                                                            .Take(scrollSize)
                                                            .Query(q => query)
                                                            .Scroll(scrollTimeout));
            }

            if (!initialResponse.IsValid || string.IsNullOrEmpty(initialResponse.ScrollId))
            {
                throw new Exception(initialResponse.ServerError.Error.Reason);
            }

            if (initialResponse.Documents.Any())
            {
                foreach (var dotace in initialResponse.Documents)
                {
                    yield return(dotace);
                }
            }

            string scrollid           = initialResponse.ScrollId;
            bool   isScrollSetHasData = true;

            while (isScrollSetHasData)
            {
                ISearchResponse <Dotace> loopingResponse = _esClient.Scroll <Dotace>(scrollTimeout, scrollid);
                if (loopingResponse.IsValid)
                {
                    foreach (var dotace in loopingResponse.Documents)
                    {
                        yield return(dotace);
                    }
                    scrollid = loopingResponse.ScrollId;
                }
                isScrollSetHasData = loopingResponse.Documents.Any();
            }

            _esClient.ClearScroll(new ClearScrollRequest(scrollid));
        }
예제 #2
0
        public static IEnumerable <OsobaES> YieldAllPoliticians(string scrollTimeout = "2m", int scrollSize = 1000)
        {
            ISearchResponse <OsobaES> initialResponse = _esClient.Search <OsobaES>
                                                            (scr => scr.From(0)
                                                            .Take(scrollSize)
                                                            .Query(_query => _query.Term(_field => _field.Status, (int)Osoba.StatusOsobyEnum.Politik))
                                                            .Scroll(scrollTimeout));

            if (!initialResponse.IsValid || string.IsNullOrEmpty(initialResponse.ScrollId))
            {
                throw new Exception(initialResponse.ServerError.Error.Reason);
            }

            if (initialResponse.Documents.Any())
            {
                foreach (var osoba in initialResponse.Documents)
                {
                    yield return(osoba);
                }
            }

            string scrollid           = initialResponse.ScrollId;
            bool   isScrollSetHasData = true;

            while (isScrollSetHasData)
            {
                ISearchResponse <OsobaES> loopingResponse = _esClient.Scroll <OsobaES>(scrollTimeout, scrollid);
                if (loopingResponse.IsValid)
                {
                    foreach (var osoba in loopingResponse.Documents)
                    {
                        yield return(osoba);
                    }
                    scrollid = loopingResponse.ScrollId;
                }
                isScrollSetHasData = loopingResponse.Documents.Any();
            }

            _esClient.ClearScroll(new ClearScrollRequest(scrollid));
        }
예제 #3
0
        public IEnumerable <T> GetAllData <T>(string scrollTimeout = "2m", int scrollSize = 1000) where T : class
        {
            ISearchResponse <T> initialResponse = this.client.Search <T>
                                                      (scr => scr.From(0)
                                                      .Take(scrollSize)
                                                      .MatchAll()
                                                      .Scroll(scrollTimeout));

            List <T> results = new List <T>();

            if (!initialResponse.IsValid || string.IsNullOrEmpty(initialResponse.ScrollId))
            {
                throw new Exception(initialResponse.ServerError.Error.Reason);
            }

            if (initialResponse.Documents.Any())
            {
                results.AddRange(initialResponse.Documents);
            }

            string scrollid           = initialResponse.ScrollId;
            bool   isScrollSetHasData = true;

            while (isScrollSetHasData)
            {
                ISearchResponse <T> loopingResponse = client.Scroll <T>(scrollTimeout, scrollid);
                if (loopingResponse.IsValid)
                {
                    results.AddRange(loopingResponse.Documents);
                    scrollid = loopingResponse.ScrollId;
                }
                isScrollSetHasData = loopingResponse.Documents.Any();
            }

            client.ClearScroll(new ClearScrollRequest(scrollid));
            return(results);
        }