使用NEST 2.x与滚动的ElasticSearch查询不返回结果 [英] ElasticSearch query using NEST 2.x with scroll is not returning result

查看:271
本文介绍了使用NEST 2.x与滚动的ElasticSearch查询不返回结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从弹性搜索中根据消息发生检索所有数据,我认为如果我使用Scroll我可以循环直到文档搜索结束,但是以下查询返回Documents = 0但Total = 1954:

  var response = client.Search< Log4Net>(s => s 
.Query(q => QueryString(qs => qs
.DefaultField(m => m.Message).Query(\+ message +\)))
.SearchType(SearchType。扫描)
.Scroll(60s));
while(response.Documents.Any())
{
var request = new BulkRequest();
request.Refresh = true;
request.Consistency = Consistency.One;
request.Operations = new List< IBulkOperation>();
foreach(var item in response.Documents)
{
request.Operations.Add(new BulkIndexOperation< Log4Net>(item));
}

var result = client.Bulk(request);

response = client.Scroll< Log4Net>(60s,response.ScrollId);
}

该响应。如果我使用滚动,文档将会空,如果我删除并获得头1000个消息,我可以得到的数据,我如何使用滚动?是否有什么问题?

解决方案

如果您指定 .SearchType(SearchType.Scan),第一个响应不包含任何文档;它将为您提供通过使用 .ScrollId 在滚动条件下返回的 .Total 属性中的总文档。滚动请求中的响应。



如果您不指定 .SearchType(SearchType.Scan),则第一个回应将包含第一组文件。



这在Elasticsearch而不是NEST中有所区别。 Search html .Scan 实际上在2.1.0中不推荐使用,但仍支持NEST 2.x,因为它支持所有次要版本的Elasticsearch 2.x。


I'm trying to retrieve all data from the elasticsearch based on a message occurrence, i figured that if i used Scroll i could loop until the document search end but the following query returns Documents = 0 but Total = 1954:

var response = client.Search<Log4Net>(s => s
                                            .Query(q => q.QueryString(qs => qs
                                             .DefaultField(m => m.Message).Query("\"" + message + "\"")))
                                             .SearchType(SearchType.Scan)
                                             .Scroll("60s"));
        while (response.Documents.Any())
        {
            var request = new BulkRequest();
            request.Refresh = true;
            request.Consistency = Consistency.One;
            request.Operations = new List<IBulkOperation>();
            foreach (var item in response.Documents)
            {
                request.Operations.Add(new BulkIndexOperation<Log4Net>(item));
            }

            var result = client.Bulk(request);

            response = client.Scroll<Log4Net>("60s", response.ScrollId);
        }

the response.Document is coming empty if i use the scroll, if i remove and get the first 1000 messages i can get the data, is anything wrong with how i'm using the Scroll?

解决方案

If you specify .SearchType(SearchType.Scan), the first response doesn't contain any documents; It will give you the total documents in the .Total property that will be returned by scrolling using the .ScrollId on the response in a scroll request.

If you don't specify .SearchType(SearchType.Scan), the first response will contain the first set of documents.

This is a difference in Elasticsearch and not NEST. SearchType.Scan is actually deprecated in 2.1.0, but is still in NEST 2.x as it supports all minor versions of Elasticsearch 2.x.

这篇关于使用NEST 2.x与滚动的ElasticSearch查询不返回结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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