弹性搜索多条件查询

问题描述 投票:0回答:1

我是弹性搜索的新手,并尝试使用以下条件查询我存储的日志:从最后一小时返回所有“致命”级别字段。这是我运行的最后一个返回错误的代码:

    GET /eu-multitenant*/_search
{
  "query": 
  { "bool": {
    "should": [
        "match": {"level": "fatal" },
        "range": {"@timestamp": {"gte": "now-1h"}}
      ]
  }

  },
  "_source": ["d.Message","@timestamp"],
  "sort": { "@timestamp" : {"order" : "desc"}},
  "size": 100
}    

这是错误:

  "error": {
    "root_cause": [
      {
        "type": "json_parse_exception",
        "reason": "Unexpected character (':' (code 58)): was expecting comma to separate Array entries\n at [Source: org.elasticsearch.common.bytes.BytesReference$MarkSupportingStreamInputWrapper@4be698a; line: 5, column: 17]"
      }
    ],

感谢您的帮助。

elasticsearch
1个回答
0
投票

我从发布问题和找到我的错误中获得了一些灵感。我没有使用{}包围不同的查询条件。

GET /eu-multitenant*/_search
{
  "query": 
  { "bool": {
    "must": [
        {"match": {"level": "fatal" }},
        {"range": {"@timestamp": {"gte": "now-24h"}}}
      ]
  }

  },
  "_source": ["d.Message","@timestamp"],
  "sort": { "@timestamp" : {"order" : "desc"}},
  "size": 100
}
© www.soinside.com 2019 - 2024. All rights reserved.