elasticsearch - 查询多个索引是可能的吗?

use*_*226 36 elasticsearch

我有一个包含3个索引的elasticsearch集群:

/users/user
/events/visit
/events/register
/pages/page
Run Code Online (Sandbox Code Playgroud)

所以,现在我需要运行处理多个索引的查询.

例如:获取在第X页中注册的用户的性别. (要获取此信息,我需要来自多个索引的信息.)

这可能吗?也许整合hadoop?

小智 42

这在Elasticsearch本身很容易!无论何时您指定索引,都可以用逗号分隔其他索引.

curl -XGET 'http://localhost:9200/index1,index2/_search?q=yourQueryHere'
Run Code Online (Sandbox Code Playgroud)

您还可以使用_all搜索所有索引.

curl -XGET 'http://localhost:9200/_all/_search?q=yourQueryHere'
Run Code Online (Sandbox Code Playgroud)

这是来自elasticsearch网站的一些有用的文档.这个网站有很多信息,但有时候有点难以找到,IMO.

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-search.html http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/multi-index.html

  • @Brian 我们可以根据索引来限制结果吗?假设我们想要索引 1 的前 5 个结果和索引 2 的前 5 个结果。我们可以在弹性搜索中实现这一点吗? (2认同)

Pav*_*rma 6

通过不将搜索限制为特定的索引或类型,我们可以搜索集群中的所有文档。Elasticsearch将搜索请求并行转发到集群中每个分片的主数据库或副本。

       1)/users,events,pages/_search : Search all types in the users,events and pages

       2)/u*,e*,p*/_search : Search all types in any indices beginning with u,e or beginning with p

       3)/events/visit,register/_search : Search types visit and register in the events index

       4) /_all/user,visit,register,page/_search : Search types users,events and pages in specified indices
Run Code Online (Sandbox Code Playgroud)