在Elasticsearch中,一般的查询都支持多索引。 只有文档API或者别名API等不支持多索引操作,因此本篇就翻译一下多索引相关的内容。
首先,先插入几条数据:
$ curl -XPOST localhost:9200/test1/test/1 -d '{"name":"test1"}'
$ curl -XPOST localhost:9200/test1/test/2 -d '{"name":"test1"}'
$ curl -XPOST localhost:9200/test2/test/1 -d '{"name":"test1"}'
这样,ES中就存在了两个索引,三条数据。
最基本的就是这种数组的风格,比如使用逗号进行分隔:
$ curl -XPOST 'http://localhost:9200/test*/_search?pretty' -d '{"query" : {"match_all" : {}}}'
{
"took" : 8,
"timed_out" : false,
"_shards" : {
"total" : 10,
"successful" : 10,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : 1.0,
"hits" : [ {
"_index" : "test1",
"_type" : "test",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"name" : "test1"
}
}, {
"_index" : "test1",
"_type" : "test",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"name" : "test1"
}
}, {
"_index" : "test2",
"_type" : "test",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"name" : "test1"
}
} ]
}
}
也可以在索引部分直接使用_all关键字代表匹配所有的索引。
$ curl -XPOST localhost:9200/_all/_search?pretty -d '{"query":{"match_all":{}}}'
$ curl -XPOST localhost:9200/test*/_search?pretty -d '{"query":{"match_all":{}}}'
最后可以通过add(+)添加一个索引,使用remove(-)去掉一个索引
$ curl -XPOST localhost:9200/-logstash*,+test*/_search?pretty -d '{"query":{"match_all":{}}}'
所有的多索引API支持以下url查询字符串参数
控制是否忽略所指定的具体索引不可用,这包括所有不存在或关闭的指数。可以指定真或假。
假设我现在指定查询一个不存在的索引
true:
当使用匹配表达式没有正确的索引时,是否正常
true:
false:
通配的索引时open还是closed
假设现在有logstash-narilog-2015.11.25索引处于关闭,logstash-narilog-2015.11.24索引处于open
open:
closed:
以上几个参数都可以在URI参数中设置,默认参数是根据所使用的API来决定。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有