1

I'm using the elasticsearch javascript API, 1.5, as currently 1.5 is the latest version of ElasticSearch which AWS elasticsearch supports.

The function in javascript which I am suppose to use works given the following template

{
  _source: ['inner_hits'],
  size: `{{size}}{{^size}}10{{/size}}`,
  from: `{{from}}{{^from}}0{{/from}}`,
  filter: {
    prefix: {
      series: `{{series}}`,
      isbn: `{{isbn}}`,
    },
  },
}

The current filter works, but doesn't allow an array of 'series', or 'isbns' to be passed into the filter. I can't use the following filter object

  filter: {
    terms: {
      series: [`{{series}}`],
      isbn: [`{{isbn}}`],
    },
  },

because if series or isbn is not passed in, no book matches an empty string, even if I passed in a default value, it would have to match every book, which would mean it would have to contain all series, and all isbns.

Ideally, I would just write a normal mustache file, and use pre-registered templates the way described here.

This describes two ways of storing templates on the cluster, first storing them in the config/scripts directory, which I don't have access to on AWS elasticsearch, and secondly, passing in the templates as a string to an index called ".scripts".

For the second option i'm unaware of how to do this using the elasticsearch.js api, so I would have to do it another way, and I can't find an example of this online.

alexwlchan
  • 5,699
  • 7
  • 38
  • 49
Ryan White
  • 2,366
  • 1
  • 22
  • 34

0 Answers0