Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 779
Nate Sullivan Avatar asked Mar 16 '17 20:03

Nate Sullivan


2 Answers

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

like image 103
nimrodm Avatar answered Nov 18 '22 17:11

nimrodm


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."
    }
  }
}
like image 38
Val Avatar answered Nov 18 '22 19:11

Val