apache - Elasticsearch 查询上下文与过滤上下文

标签 apache elasticsearch lucene

我对 ElasticSearch 查询 DSL 的查询上下文和过滤上下文有点困惑。我有以下 2 个查询。两个查询返回相同的结果,第一个查询评估分数,第二个查询不返回。哪个更合适?

第一个查询:-

 curl -XGET 'localhost:9200/xxx/yyy/_search?pretty' -d'
 {
   "query": {
     "bool": {
       "must": {
         "terms": { "mcc" : ["5045","5499"]}
       },
       "must_not":{
         "term":{"maximum_flag":false}
       },                          
       "filter": {
         "geo_distance": {
           "distance": "500",
           "location": "40.959334, 29.082142"
         }                                   
       }
     }
   }
 }'

第二个查询:-

 curl -XGET 'localhost:9200/xxx/yyy/_search?pretty' -d'
 {
   "query": {
     "bool" : {
       "filter": [
         {"term":{"maximum_flag":true}},
         {"terms": { "mcc" : ["5045","5499"]}}
       ],
       "filter": {
         "geo_distance": {
            "distance": "500",
            "location": "40.959334, 29.082142"
         }                                   
       }
     }
   }
 }'

谢谢,

最佳答案

在官方指南中你有很好的解释:

Query context

A query clause used in query context answers the question “How well does this document match this query clause?” Besides deciding whether or not the document matches, the query clause also calculates a _score representing how well the document matches, relative to other documents.

Query context is in effect whenever a query clause is passed to a query parameter, such as the query parameter in the search API.

Filter context

In filter context, a query clause answers the question “Does this document match this query clause?” The answer is a simple Yes or No — no scores are calculated. Filter context is mostly used for filtering structured data, e.g.

Does this timestamp fall into the range 2015 to 2016? Is the status field set to "published"? Frequently used filters will be cached automatically by Elasticsearch, to speed up performance.

Filter context is in effect whenever a query clause is passed to a filter parameter, such as the filter or must_not parameters in the bool query, the filter parameter in the constant_score query, or the filter aggregation.

https://www.elastic.co/guide/en/elasticsearch/reference/2.3/query-filter-context.html

关于您的情况,我们需要更多信息,但考虑到您正在寻找精确值,过滤器会更适合它。

关于apache - Elasticsearch 查询上下文与过滤上下文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41251500/

相关文章:

java - 如何在带有 weblogic 的 java 项目中配置与 apache 无关的静态文件夹

elasticsearch - Elasticsearch中的快速关键词提取

amazon-web-services - 消息”:"User: anonymous is not authorized to perform: iam:PassRole

java - Lucene CustomScoreQuery 不从 FunctionQuery 的 FieldSource 传递值

apache - 使用Apache的.htaccess对子目录进行密码保护

Apache 负载均衡 tomcat websocket

mysql - 终止了 Amazon Linux 中的 'mysqld' 进程 - 一切似乎都正常,真的吗?

elasticsearch - 在 Elasticsearch 查询中查找最大日期

lucene - pattern_replace 中的不区分大小写的替换

search - 使用 DIH (DataImportHandler) 的动态列名