4

I hope someone can explain me why I'm having this issue: I want to validate an ES (in version 7.4) query before launch it, every thing works fine if the query has no aggs clause but, if the query has aggs, ES says it's a no valid query, what is driving my crazy is the query works fine in ES but at the same time ES tells me it's not a valid query.

I think is because ES do not validate queries with aggs but I would love to "be sure", I've read the documentation and I found no clue.

Thanks a lot.

This is an example of ES query I want to validate

        "query": {
            "bool": {
                "must": [
                    {
                        "match_phrase": {
                            "probe_id": {
                                "query": "probe id"
                            }
                        }
                    }
                ]
            }
        },
        "aggs": {
            "agg_by_hours": {
                "terms": {
                    "field": "hours",
                    "size": 24,
                    "order": {
                        "_term": "desc"
                    }
                }
            }
        }
    }```
Val
  • 207,596
  • 13
  • 358
  • 360

1 Answers1

4

The validate query API only supports the query section not the aggs section. Nothing else, not even _source, sort, from and size. You can also see this in the source code.

If you add ?explain=true to your URL, you'll see an explanation like:

{
  "valid" : false,
  "error" : "org.elasticsearch.common.ParsingException: request does not support [aggs]"
}

So you can definitely validate your query but only take the query part and you'll be fine.

Val
  • 207,596
  • 13
  • 358
  • 360