Elasticsearch查询问题,范围格式错误的查询,预期为END_OBJECT,但找到FIELD_NAME

时间:2019-10-13 16:49:50

标签: elasticsearch

我无法弄清楚此查询出了什么问题。 “范围”和“存在”两者都是独立工作的,但是我一起得到parsing expectionrange malformed query, expected END_OBJECT but found FIELD_NAME。有人可以找出这个查询有什么问题吗?

{
"query": {
  "range":{
     "@timestamp":{
        "gte":"2019-08-04T11:00:00",
        "lt":"2019-10-04T12:00:00"
     }
  },
  "exists": {
      "field": "params.zone"
  }  

},
"_source": ["@timestamp", "params.zone"]
}

1 个答案:

答案 0 :(得分:1)

如果您想像合并rangeexists一样合并多个查询,则需要使用bool query并确定哪些子句是强制性的(must ),可选(should),过滤器(filter)或不应在结果中显示(must_not

可能有效的查询如下所示(您的子句在此示例中是必需的):

{
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "@timestamp": {
              "gte": "2019-08-04T11:00:00",
              "lt": "2019-10-04T12:00:00"
            }
          }
        },
        {
          "exists": {
            "field": "params.zone"
          }
        }
      ]
    }
  },
  "_source": [
    "@timestamp",
    "params.zone"
  ]
}