弹性搜索查询检索所有记录NEST [英] Elasticsearch search query to retrieve all records NEST

查看:163
本文介绍了弹性搜索查询检索所有记录NEST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在文件夹中有很少的文档,我想检查这个文件夹中的所有文档是否被索引。要做到这一点,对于文件夹中的每个文档名称,我想运行一个循环,为ES中索引的文档进行比较。所以我想检索所有的文件。

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 run through a loop for the documents indexed in ES and compare. So I want to retrieve all the documents.

同样的问题,有一些其他可能的重复项,如检索(ElasticSearch)NEST查询中的所有记录和< a href =https://stackoverflow.com/questions/8829468/elasticsearch-query-to-return-all-recordstitle =查询返回所有记录>在此输入链接描述,但他们没有帮助我当时的文档已经改变了(目前文档中没有扫描)

There are few other possible duplicates of the same question like retrieve all records in a (ElasticSearch) NEST query and enter link description here but they didnt help me as the documentation has changed from that time.(there is nothing about scan in the current documentation)

我尝试使用 client.search< T> ;()。但是,根据文档,将检索默认的10个结果。我想得到所有的记录,没有提到记录的大小? (因为索引的大小更改)

I tried using client.search<T>() . But as per the documentation, a default number of 10 results are retrieved. I would like to get all the records without mentioning the size of records ? (Because the size of the index changes)

或者可以先获取索引的大小,然后将此数字作为输入发送到大小以获取所有文件和循环?

Or is it possible to get the size of the index first and then send this number as input to the size to get all the documents and loop through?

推荐答案

这是我如何解决我的问题。希望这可以帮助。 (参考 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

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<string> indexedList = new List<string>();
var scanResults = client.Search<ClassName>(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<ClassName>("10m", scanResults.ScrollId);
        while (results.Documents.Any())
        {
            foreach(var doc in results.Fields)
            {
                indexedList.Add(doc.Value<string>("propertyName"));
            }

            results = client.Scroll<ClassName>("10m", results.ScrollId);
        }



编辑



EDIT

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

这篇关于弹性搜索查询检索所有记录NEST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆