sudo-suhas/elastic-builder

Pre-registered queries

kamyarghajar opened this issue · 4 comments

How can I generate a mustache pre-registered query defined in the following section:

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html#pre-registered-templates

See https://elastic-builder.js.org/docs/#searchtemplate. An example:

const templ = esb.searchTemplate('id', '<templateName>').params({
    query_string: 'search for these words'
});

Hope that answers your question. I am closing the issue but feel free to continue the discussion.

Thank you but no, this is not what I want to do. I need to register the template as mentioned in the link I have provided not to call the template with parameters.

I suppose you could use esb.script():

esb.script()
  .lang('mustache')
  .source({
    "query": {
      "match": { "title": "{{query_string}}" }
   }
 })
// toJSON:
{
  "lang": "mustache",
  "source": {
    "query": {
      "match": {
        "title": "{{query_string}}"
      }
    }
  }
}

You could use this and POST it by setting it as the script field value. But this isn't something elastic-builder aims to supports so your mileage may vary.

Oh, so elastic-builder is not supposed to handle these kinds of queries like indexing, aliasing or so.
It would be a great improvement for elastic-builder to support all the elastic requests' bodies not only queries. Well thank you @sudo-suhas