您的位置:首页 > 其它

Elasticsearch——多索引的使用

2017-01-03 00:00 176 查看
首先,先插入几条数据:

$ 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 localhost:9200/test1,test2/_search?pretty -d '{"query":{"match_all":{}}}'
{
"took" : 5,
"timed_out" : false,
"_shards" : {
"total" : 10,
"successful" : 10,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : 1.0,
"hits" : [ {
"_index" : "test1",
"_type" : "test",
"_id" : "1",
"_score" : 1.0,
"_source":{"name":"test1"}
}, {
"_index" : "test2",
"_type" : "test",
"_id" : "1",
"_score" : 1.0,
"_source":{"name":"test1"}
}, {
"_index" : "test1",
"_type" : "test",
"_id" : "2",
"_score" : 1.0,
"_source":{"name":"test1"}
} ]
}
}


_all

也可以在索引部分直接使用
_all
关键字代表匹配所有的索引:

$ curl -XPOST localhost:9200/_all/_search?pretty -d '{"query":{"match_all":{}}}'


通配风格

elasticsearch还支持使用统配的风格,如使用*匹配任意字符:

$ 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":{}}}'


另外介绍几个文档中常用的参数:

1 ignore_unavailable

是否忽略不可用的索引

2 allow_no_indices

当没有可用的索引时,是否正常

3 expand_wildcards

统配的对象,是open的索引,还是closed的索引

这几个参数都可以在url参数中设置。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: