Elasticsearch:批量搜索可能吗?

pio*_*rek 10 elasticsearch elasticsearch-dsl elasticsearch-query

我知道有批量索引操作的支持.但搜索查询是否也可以这样做?我想发送许多不同的无关查询(进行精确/召回测试),使用批量查询可能会更快

Val*_*Val 14

是的,您可以使用多搜索API/_msearch端点一次发送任意数量的查询.

curl -XPOST localhost:9200/_msearch -d '
{"index" : "test1"}
{"query" : {"match_all" : {}}, "from" : 0, "size" : 10}
{"index" : "test2"}
{"query" : {"match_all" : {}}}
'
Run Code Online (Sandbox Code Playgroud)

您将获得一个responses数组,其中包含每个查询的响应,其顺序与请求中的顺序相同.

注意:

  1. 确保用换行符分隔每一行
  2. 确保在上次查询后添加额外的换行符.