这个主要是演示下如何一次性搜索多个索引(index)
首先创建2个索引,如下
PUT /test1/type1/apple
{
"name":"apple",
"color":"red",
"price":8.8
}
PUT /test1/type1/pear
{
"name":"pear",
"color":"yellow",
"price":4.5
}
然后用以下方式都可以实现一次搜索多个索引
序号 | 实现方式 | 说明 |
1 | GET /test1,test2/_search | 同时搜索两个index下的数据 |
2 | GET /*1,*2/_search | 按照通配符去匹配多个索引 |
这个主要是演示下如何一次性搜索多个类型(type)
首先在test1索引下再创建一个type11的类型,如下
PUT /test1/type11/specialpear
{
"name":"specialpear",
"color":"yellow",
"price":10
}
PUT /test2/type11/specialapple
{
"name":"specialapple",
"color":"red",
"price":12
}
然后用以下方式都可以实现一次搜索多个类型
序号 | 实现方式 | 说明 |
1 | GET /test1/type1,type11/_search | 搜索一个index下多个type的数据 |
2 | GET /test1,test2/type11/_search | 搜索多个index下同一个type的数据 |
3 | GET /_all/type1,type2/_search | 搜索所有index下的指定type的数据 |
1. 客户端向ES集群发送一个搜索请求,会把请求打到所有的primary shard上,这是因为每个primary shard都包含部分数据,都可能包含搜索的部分结果.
2. 如果一个primary shard有对应的replica shard,那么搜索请求也可能转发到对应的replica shard上。