弹性搜索范围查询和范围过滤器之间的差异 [英] Difference between Elasticsearch Range Query and Range Filter

查看:251
本文介绍了弹性搜索范围查询和范围过滤器之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在日期范围内查询弹性搜索文档。我现在有两个选择,对我来说都很好。已经测试了两者。
1.范围查询
2.范围过滤器

I want to query elasticsearch documents within a date range. I have two options now, both work fine for me. Have tested both of them. 1. Range Query 2. Range Filter

由于我现在有一个小数据集,我无法测试两者的性能的他们。这两者有什么区别?哪一个会导致更快的文档检索和更快的响应?

Since I have a small data set for now, I am unable to test the performance for both of them. What is the difference between these two? and which one would result in faster retrieval of documents and faster response?

推荐答案

查询和过滤器之间的主要区别与得分。查询返回每个文档的相对排名得分的文档。过滤器不。这种差异允许过滤器更快,有两个原因。首先,它不会导致计算每个文档的分数的成本。第二,它可以缓存结果,因为它不必处理可能的分数变化的时刻 - 它只是一个布尔,真的,文档是否匹配?

The main difference between queries and filters has to do with scoring. Queries return documents with a relative ranked score for each document. Filters do not. This difference allows a filter to be faster for two reasons. First, it does not incur the cost of calculating the score for each document. Second, it can cache the results as it does not have to deal with possible changes in the score from moment to moment - it's just a boolean really, does the document match or not?

从文档中:


过滤器通常比查询更快,因为:

Filters are usually faster than queries because:

他们不必计算每个文档的相关性_score -
答案只是一个布尔值是的,文档匹配过滤器或
否,文档不匹配过滤器。大多数
过滤器的结果可以缓存在内存中,从而使后续执行更快。

they don’t have to calculate the relevance _score for each document —  the answer is just a boolean "Yes, the document matches the filter" or "No, the document does not match the filter". the results from most filters can be cached in memory, making subsequent executions faster.

实际上,问题你是否以任何方式使用相关性分数?如果没有,过滤器是要走的路。如果你这样做,滤镜仍然可能是有用的,但应该被用于有意义的地方。例如,如果您的文档中有一个语言字段(例如,以EN为例),并希望通过语言查询相关性分数,则可以将文本搜索的查询与一个过滤器语言。过滤器将使用英文缓存所有文档的文档ID,然后查询可以应用于该子集。

As a practical matter, the question is do you use the relevance score in any way? If not, filters are the way to go. If you do, filters still may be of use but should be used where they make sense. For instance, if you had a language field (let's say language: "EN" as an example) in your documents and wanted to query by language along with a relevance score, you would combine a query for the text search along with a filter for language. The filter would cache the document ids for all documents in english and then the query could be applied to that subset.

我已经简化了一点,但这是基础。阅读的好地方:

I'm over simplifying a bit, but that's the basics. Good places to read up on this:

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-filtered-query.html

http://www.elasticsearch.org/guide/en/elasticsearch/reference/0.90/query-dsl-filtered-query.html

http://exploringelasticsearch.com/searching_data.html

http://elasticsearch-users.115913 .n3.nabble.com / Filters-vs-Queries-td3219558.html

这篇关于弹性搜索范围查询和范围过滤器之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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