繁体   English   中英

Elasticsearch和查询

[英]Elasticsearch AND Query

我正在尝试做这样的事情:

SELECT * FROM x WHERE __account_id = 5 AND __import_id IN [1,2,3]

这是我的ES查询:

body = {
    "query": {
        "filtered" : { 
            "filter" : {
                "term" : { 
                    "__account_id" : account.id,
                    "__import_id": [x['id'] for x in ingested_imports]
                }
            }
        }
    }
}

结果似乎仅根据__account_id过滤,而没有根据__import_id过滤。 我究竟做错了什么?

您需要在bool查询中包装termterms过滤器,因为这两个子句必须匹配。

{
  "query":{
    "filtered":{
      "filter":{
        "bool":{
          "must":[
            {
              "term":{
                "__account_id":5
              }
            },
            {
              "terms":{
                "__import_id":[1, 2, 3]
              }
            }
          ]
        }
      }
    }
  }
}

暂无
暂无

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

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