2

I am trying to solve parsing exception of my search query. I would like to get some help there :)

The exception reason: '[1:65] [bool] failed to parse field [filter]' message:'x_content_parse_exception'

My search:

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);

2 Answers 2

4

You are missing [] around the filter clause, try out this below query

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);

In JSON format, it will be like this

{
  "query": {
    "bool": {
      "filter": [
        {
          "terms": {
            "MachineId": [
              "mo3",
              "mo2"
            ]
          }
        },
        {
          "range": {
            "timestamp": {
              "gte": "now-${lastMinutes}m",
              "lte": "now"
            }
          }
        }
      ]
    }
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

@RanNissan I have added the query in JSON format also, try to match the brackets from that, as the error clearly shows that the query is not properly formed.
1

the exception message also appears if the query string is longer than 10000.

V8 ElasticSearchClient's JsonpUtils has a default max length of 10000, cutting longer queries (and adding "..."). So JSON no longer is valid.

We had to set a new max length with "JsonpUtils.maxToStringLength(500000);" (at your own risk...)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.