Elasticsearch 查询结果 'No query registered for [must]'

Elasticsearch query results in 'No query registered for [must]'

ES 2.3 版,我正在尝试 运行 使用过滤器和查询在 elasticsearch 服务器上进行搜索。我有几个要搜索的键,一些 has 是结果的一部分, 'host' 键 should 在结果(因为我想要来自多个主机的结果,而不仅仅是一个)

这是我正在尝试 运行 的查询,出于某种原因,我收到一条错误消息 - "search_phase_execution_exception - No query registered for [must]"

{
    "query": {
        "filtered": {
            "filter": {
                "bool": {
                    "must": [{
                        "range": {
                            "@timestamp": {
                                "gte": 1503751766908,
                                "lte": 1503751786908,
                                "format": "epoch_millis"
                            }
                        },
                        "query": {
                            "should": [{
                                "match_phrase": {
                                    "host": "host1"
                                }
                            }, 
                            {"match_phrase": {
                                "host": "host2"
                            }
                            }],
                            "must": [{
                                "match_phrase": {
                                    "key1": "value1"
                                }
                            }]
                        }
                    }]
                }
            }
        }
    }
}

你有点混淆了,试试这个:

{
  "query": {
    "bool": {
      "must": [
        {
          "match_phrase": {
            "key1": "value1"
          }
        },
        {
          "range": {
            "@timestamp": {
              "gte": 1503751766908,
              "lte": 1503751786908,
              "format": "epoch_millis"
            }
          }
        }
      ],
      "minimum_should_match": 1,
      "should": [
        {
          "match": {
            "host": "host1"
          }
        },
        {
          "match": {
            "host": "host2"
          }
        }
      ]
    }
  }
}