Using the Ranking API with Search Templates

Hi folks, hope this is the right place to ask:

For our search use case, we're developing search templates (with mustache, including conditional clauses). In production, our users have identified some problematic cases we're taking into account for further development. To test the quality of the search results, we've so far relied on manual testing. However, since our user base is about to expand and the number of critical cases might as well, we'd like to adopt a somewhat more automated approach, e.g. with the ranking API. Is there a way to call a search template from within a rank_eval all? Otherwise it seems that we'd have to always update all the queries put toward ranking instead of just the template, which obviously is less convenient.

OK just after asking I found that it is possible to use templates as described here, but the question of using defined search templates is still open.

Or, alternatively, can templates written in mustache be used? Along the lines of

GET foo_bar/_rank_eval
{
  [...]
  "templates": [
    {
      "id": "mustache_test",
      "template": {
        "script": {
          "lang": "mustache",
          "source": """
            "query": {
              "match": {
                "foo": {
                  "query": {{#bar}}
                }
              }
            }
          """
        }
      }
    }
  ]
  [...]

For future reference, we found a syntax that apparently works:

GET foo_bar/_rank_eval
{
  "templates": [
    {
      "id": "mustache_test",
      "template": {
        "lang": "mustache",
        "source": """
        {
          "query": {
            {{#bar}}
            "match": {
              "foo": {
                "query": "{{bar}}"
              }
            }
            {{/bar}}
          }
        }
        """
      }
    }
  ],
  "requests": [...],
  "metric": {...}
  }
}
1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.