elasticsearch 索引会自动创建很多索引么

在Elasticsearch中,一般的查询都支持多索引。
只有文档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 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关键字代表匹配所有的索引:
$ 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&:{}}}'
另外介绍几个文档中常用的参数:
是否忽略不可用的索引
2 allow_no_indices
当没有可用的索引时,是否正常
3 expand_wildcards
统配的对象,是open的索引,还是closed的索引
这几个参数都可以在url参数中设置。
阅读(...) 评论()ElasticSearch绱㈠紩浼樺寲 - zzm - ITeye鍗氬?
鍗氬?鍒嗙被锛

我要回帖

更多关于 elasticsearch 建索引 的文章

 

随机推荐