Elasticsearch——多索引的使用

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"}
    } ]
  }
}

猜你喜欢

转载自blog.csdn.net/u010357298/article/details/78365822
今日推荐