.NET5(C#) ElasticSearch7 Scroll示例

2021/7/26 20:37:35

本文主要是介绍.NET5(C#) ElasticSearch7 Scroll示例,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

search_type=scan removed
The scan search type was deprecated since version 2.1.0 and is now removed. All benefits from this search type can now be achieved by doing a scroll request that sorts documents in _doc order, for instance:

网上流传的老办法不行了。
实际上看,sort不用_doc也OK

代码

using Nest;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;

namespace ESScrollReader
{
    class Program
    {

        public static readonly string url = "http://192.168.0.1:9200/";
        static void Main(string[] args)
        {
            ScrollSearch("test_index");
        }
        public static void ScrollSearch(string index)
        {
            var settings = new ConnectionSettings(new Uri(url)).DefaultIndex(index);
            var client = new ElasticClient(settings);
            var searchResponse = client.Search<dynamic>(s => s.Sort(sort => sort.Descending("time")).Size(10000).Scroll("1s"));
            
            while (searchResponse.Documents.Any())
            {
                searchResponse = client.Scroll<dynamic>("1s", searchResponse.ScrollId);
                var d = (Dictionary<string, object>)searchResponse.Documents.First<dynamic>();
                //Do sth.
            }
        }
    }
}



这篇关于.NET5(C#) ElasticSearch7 Scroll示例的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程