Elasticsearch查询导致'没有为[必须]注册的查询

时间:2017-08-26 13:17:57

标签: elasticsearch elasticsearch-query

ES版本2.3,我正在尝试使用filter& amp ;;在elasticsearch服务器上运行搜索查询。我有几个想要搜索的键,一些 成为结果的一部分,'host'键应该在结果中(因为我想要结果来自多个主机,而不仅仅是一个)

这是我正在尝试运行的查询,由于某种原因我收到错误 - “search_phase_execution_exception - 没有为[必须]注册的查询”

{
    "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"
                                }
                            }]
                        }
                    }]
                }
            }
        }
    }
}

1 个答案:

答案 0 :(得分:1)

你把它混合了一点,试试这个:

{
  "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"
          }
        }
      ]
    }
  }
}