【问题标题】:Elasticsearch '[bool] failed to parse field [filter]' exceptionElasticsearch '[bool] 无法解析字段 [filter]' 异常
【发布时间】:2020-11-15 17:43:40
【问题描述】:

我正在尝试解决我的搜索查询的解析异常。 我想在那里得到一些帮助:)

异常原因: '[1:65] [bool] 无法解析字段 [filter]' 消息:'x_content_parse_exception'

我的搜索:

data = (await this.elasticClient.search({
        index: Indexes.Measurements,
        size: 10000,
        body: {
          query: {
            bool: {
              filter: {
                terms: {
                  "MachineId": ["mo3", "mo2"]
                },
                range: {
                  '@timestamp': {
                    gte: `now-${lastMinutes}m`,
                    lte: 'now'
                  }
                }
              }
            },
          },
          sort : [{ "@timestamp" : "desc" }]
      }})).body.hits.hits.map(data => data._source);

【问题讨论】:

    标签: elasticsearch elasticsearch-dsl


    【解决方案1】:

    您在filter 子句周围缺少[],请尝试以下查询

    data = (await this.elasticClient.search({
            index: Indexes.Measurements,
            size: 10000,
            body: {
              query: {
                bool: {
                  filter: [{
                    terms: {
                      "MachineId": ["mo3", "mo2"]
                    }},{
                    range: {
                      '@timestamp': {
                        gte: `now-${lastMinutes}m`,
                        lte: 'now'
                      }
                    }}]
                  }
                },
              },
              sort : [{ "@timestamp" : "desc" }]
          }})).body.hits.hits.map(data => data._source);
    

    JSON格式会是这样的

    {
      "query": {
        "bool": {
          "filter": [
            {
              "terms": {
                "MachineId": [
                  "mo3",
                  "mo2"
                ]
              }
            },
            {
              "range": {
                "timestamp": {
                  "gte": "now-${lastMinutes}m",
                  "lte": "now"
                }
              }
            }
          ]
        }
      }
    }
    

    【讨论】:

    • @RanNissan 我也添加了 JSON 格式的查询,尝试从中匹配括号,因为错误清楚地表明查询格式不正确。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-24
    • 2021-11-04
    • 1970-01-01
    • 1970-01-01
    • 2015-01-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多