ruby 将弹性搜索限制设置为“无限制”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14396582/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 05:40:12  来源:igfitidea点击:

Setting Elastic search limit to "unlimited"

rubyelasticsearch

提问by Sumit Rai

How can i get all the results from elastic search as the results only display limit to 10 only. ihave got a query like:

我怎样才能从弹性搜索中获得所有结果,因为结果只显示限制为 10。我有一个查询,如:

@data = Athlete.search :load => true do
          size 15
          query do
            boolean do
              must { string q, {:fields => ["name", "other_names", "nickname", "short_name"], :phrase_slop => 5} }
              unless conditions.blank?
                conditions.each do |condition|
                  must { eval(condition) }
                end
              end
              unless excludes.blank?
                excludes.each do |exclude|
                  must_not { eval(exclude) }
                end
              end
            end
          end
          sort do
            by '_score', "desc"
          end
        end

i have set the limit to 15 but i wan't to make it unlimited so that i can get all the data I can't set the limit as my data keeps on changing and i want to get all the data.

我已将限制设置为 15,但我不想将其设置为无限制,以便我可以获取所有数据 我无法设置限制,因为我的数据不断变化,我想获取所有数据。

采纳答案by Zach

You can use the fromand sizeparameters to page through all your data. This could be very slow depending on your data and how much is in the index.

您可以使用fromsize参数分页浏览所有数据。这可能会非常慢,具体取决于您的数据以及索引中的内容。

http://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-from-size.html

http://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-from-size.html

回答by David

Another approach is to first do a searchType: 'count', then and then do a normal search with sizeset to results.count.

另一种方法是先执行 a searchType: 'count',然后使用sizeset to执行正常搜索results.count

The advantage here is it avoids depending on a magic number for UPPER_BOUNDas suggested in this similar SO question, and avoids the extra overhead of building too large of a priority queue that Shay Banon describes here. It also lets you keep your results sorted, unlike scan.

这里的优点是它避免了依赖UPPER_BOUND这个类似的 SO 问题中建议的幻数,并避免了构建过大的优先级队列的额外开销,Shay Banon在这里描述。与scan.

The biggest disadvantage is that it requires two requests. Depending on your circumstance, this may be acceptable.

最大的缺点是它需要两个请求。根据您的情况,这可能是可以接受的。

回答by travelingbones

From the docs, "Note that from + sizecan not be more than the index.max_result_windowindex setting which defaults to 10,000". So my admittedly very ad-hoc solution is to just pass size: 10000or 10,000 minus fromif I use the fromargument.

文档中,“请注意from + size不能超过index.max_result_window默认为 10,000的索引设置”。因此,我公认的非常临时的解决方案是,如果我使用该参数则仅通过size: 10000或减去 10,000 。from

Note that following Matt's comment below, the proper way to do this if you have a larger amount of documents is to use the scroll api. I have used this successfully, but only with the python interface.

请注意,按照下面 Matt 的评论,如果您有大量文档,正确的方法是使用scroll api。我已经成功地使用了它,但仅限于 python 接口。

回答by Rachel Gallen

use the scan method e.g.

使用扫描方法,例如

 curl -XGET 'localhost:9200/_search?search_type=scan&scroll=10m&size=50' -d '
 {
    "query" : {
       "match_all" : {}
     }
 }

see here

这里