如何在多搜索中使用Elasticsearch搜索模板(_msearch)API?

How to use Elasticsearch search templates in multi search (_msearch) API?

是否可以在多重搜索 api (_msearch) 请求中使用已注册的搜索模板? 如果可以,怎么做?

我尝试在正文中给出以下查询。

POST /_msearch
{"index":"index1","type":"type1"}
{"template":{"id":"template_1"},"params":{"a":1, "b":2}}

但这会导致错误:

Parse Failure [No parser for element [template]]

我尝试将所有内容包装在一个查询中:

POST /_msearch
{"index":"index1","type":"type1"}
{"query":{"template":{"id":"template_1"},"params":{"a":1, "b":2}}}

和 POST 到 _msearch/template,但这些都不起作用。

提前致谢

目前不支持,但他们有一个开放的增强请求。 Add template support to _msearch #10885

这个功能是2016年添加的,这里是使用6.8模板的多搜索文档(目前支持最旧的ES版本):

https://www.elastic.co/guide/en/elasticsearch/reference/6.8/multi-search-template.html