如何编写查询?

时间:2019-05-20 10:57:30

标签: python elasticsearch elasticsearch-5

"search_id" : "7f2d683165",
          "uploaded_time" : "2019-05-10 15:25:35.373",
          "processing_end_time" : "2019-05-10 15:25:38.115",
          "batches" : {
            "5cd598617026837753891a2b" : {
              "is_reviewed" : false,
              "batch_name" : "T--45"
            }
          }

如何针对我是否想要("is_reviewed" : true)编写正确的查询?
我已经尝试过了:

query={"query": { "nested" : {"path" : "batches","query" : {"bool" : {"should" : [ { "match" : {"batches.is_reviewed" : true} }]}}}}}

res=es.search(index="cool",body={"query":{"match":{"pass":"true"}}})

我只希望输出"pass:true"

1 个答案:

答案 0 :(得分:0)

您可以尝试以下方法:

{
  "query": {
    "query_string": {
      "query": "batches.\\*.is_reviewed:true"
    }
  }
}

或者如果batchesnested则为:

{
  "query": {
    "nested": {
      "path": "batches",
      "query": {
        "bool": {
          "should": [
            {
              "query_string": {
                "query": "batches.\\*.is_reviewed:true"
              }
            }
          ]
        }
      }
    }
  }
}