'Is it possible to put a comment in an Elasticsearch query?

Is it possible to put a comment into an Elasticsearch query JSON? I want to be able to add some extra text to the query that's human-readable but ignored by Elasticsearch.

For example, if I have the following query:

{ "query": { "match_all": {} } }

I would like to be able to add a comment, maybe something like this:

{ "query": { "match_all": {} }, "comment": "This query matches all documents." }

Hacky workarounds (e.g., a query clause that has no effect on the results) would also be appreciated.



Solution 1:[1]

Seems like Elasticsearch does allow Javascript comments (/* */ and //) in JSON (Despite the JSON standard not supporting comments). So that's another option.

Solution 2:[2]

One solution to make this work is to use named queries, i.e. each query can be named

{
  "query": {
    "match_all": {
      "_name": "This query matches all documents."
    }
  }
}

Solution 3:[3]

by inserting # [hash symbol] ,yes you can put comment for elastic search queries in console

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 nimrodm
Solution 2 Val
Solution 3 ganivk