繁体   English   中英

Elasticsearch“必须”查询具有多个条件

[英]Elasticsearch 'must' query with multiple criteria

使用bool且必须查询时,尝试获取python-elasticsearch或curl以返回适当的结果。

我知道文档在查询中,可以用“应该”找到它; 但是,我需要满足两个条件,因此我尝试使用“必须”进行相同的查询。 当我使用“必须”时,有问题的文档不会返回。

与应

$ curl -XGET 'localhost:9200/polarion/subtype1/_search?pretty' -H 'Content-Type: application/json' -d'
{
   "query" : {
      "constant_score" : {
         "filter" : {
            "bool" : {
              "should" : [
                 { "term" : {"project" : "AMQ"}},  
                 { "term" : {"test-type" : "functional"}}]
           }
         }
      }
   }
}
'

"hits" : {
    "total" : 3,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "polarion",
        "_type" : "subtype1",
        "_id" : "AV3s-vbF8T4AI9Zj3GkM",
        "_score" : 1.0,
        "_source" : {
          "project" : "AMQ",
          "query" : "test-metrics",
          "test-type" : "functional",
          "2017-08-16" : 1916
        }
      },

必须

$ curl -XGET 'localhost:9200/polarion/subtype1/_search?pretty' -H 'Content-Type: application/json' -d'
{
   "query" : {
      "constant_score" : {
         "filter" : {
            "bool" : {
              "must" : [
                 { "term" : {"project" : "AMQ"}},  
                 { "term" : {"test-type" : "functional"}}]
           }
         }
      }
   }
}
'


{   "took" : 0,   "timed_out" : false,   "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0   },   "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : [ ]   } }

更改

{"term": {"project": "AMQ"}}

{"term": {"project": "amq"}}

或者,我们可以用match代替术语并使用“ AMQ”。

{"match": {"project": "AMQ"}}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM