Elasticsearch search query to retrieve all records NEST

前端 未结 2 783
轮回少年
轮回少年 2021-01-17 18:13

I have few documents in a folder and I want to check if all the documents in this folder are indexed or not. To do so, for each document name in the folder, I would like to

2条回答
  •  醉酒成梦
    2021-01-17 18:48

    Here is how I solved my problem. Hope this helps. (References https://www.elastic.co/guide/en/elasticsearch/client/net-api/1.x/scroll.html , https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html#scroll-search-context)

    List indexedList = new List();
    var scanResults = client.Search(s => s
                    .From(0)
                    .Size(2000)
                    .MatchAll()
                    .Fields(f=>f.Field(fi=>fi.propertyName)) //I used field to get only the value I needed rather than getting the whole document
                    .SearchType(Elasticsearch.Net.SearchType.Scan)
                    .Scroll("5m")
                );
    
            var results = client.Scroll("10m", scanResults.ScrollId);
            while (results.Documents.Any())
            {
                foreach(var doc in results.Fields)
                {
                    indexedList.Add(doc.Value("propertyName"));
                }
    
                results = client.Scroll("10m", results.ScrollId);
            }
    

    EDIT

    var response = client.Search(s => s
                             .From(fromNum)
                             .Size(PageSize)
                             .Query(q => q ....
    

提交回复
热议问题