前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Elasticsearch多索引

Elasticsearch多索引

作者头像
用户1174963
发布2018-01-17 11:26:02
1.7K0
发布2018-01-17 11:26:02
举报
文章被收录于专栏:python学习指南python学习指南

 在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

也可以在索引部分直接使用_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查询字符串参数

1 ignore_unavailable: true/false

控制是否忽略所指定的具体索引不可用,这包括所有不存在或关闭的指数。可以指定真或假。

假设我现在指定查询一个不存在的索引

true:

false:
2 allow_no_indices

 当使用匹配表达式没有正确的索引时,是否正常

true:

false:

3 expand_wildcards:true/false

通配的索引时open还是closed

假设现在有logstash-narilog-2015.11.25索引处于关闭,logstash-narilog-2015.11.24索引处于open

open:

closed:

以上几个参数都可以在URI参数中设置,默认参数是根据所使用的API来决定。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016-05-07 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 数组格式
  •  _all
  •  通配风格
  •  数学表达式风格
  • 另外介绍几个文档中常用的参数:
    • 1 ignore_unavailable: true/false
      • false:
        • 2 allow_no_indices
          • 3 expand_wildcards:true/false
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档