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

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过滤。我究竟做错了什么?

最佳答案

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

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

关于python - Elasticsearch和查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26640901/

10-13 09:38