Hocon support in Elasticsearch?

You can use comments already in Elasticsearch JSON dialect:

{
    /* this query matches all documents */
    "query" : {
        "match_all" : {
            
        }
    }
}

Note that Elasticsearch does not only use JSON for formulating queries or writing configurations, it is also the internal lingua franca used by the Jackson library which translates to Lucene field names and value structure. HOCON is a superset of JSON and does not align with such a procedure e.g. when processing duplicate keys.

Try this

PUT /test/test/1
{
    "a" : {"b":"c"},
    "a" : {"d":"e"}
}

Elasticsearch will create a document {"a":{"d":"e"}} but HOCON would create {"a":[{"b","c"},{"d":"e"}]}

While Elasticsearch JSON is valid Javascript, which fits nicely into HTTP and the Web, I find HOCON rather a burden when other languages must process it. You would have to convert back and forth with lots of boilerplate code like

val config = ConfigFactory.load(); 
val configJSON : String = 
  config.root().render( ConfigRenderOptions.concise() )

Also HOCON comes from Scala, and the Scala multiline string format used in HOCON would break e.g. Elasticsearch bulk JSON-Lines format.

1 Like