zoukankan      html  css  js  c++  java
  • 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

    也可以在索引部分直接使用_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参数中设置。

  • 相关阅读:
    LeetCode 79. 单词搜索
    LeetCode 1143. 最长公共子序列
    LeetCode 55. 跳跃游戏
    LeetCode 48. 旋转图像
    LeetCode 93. 复原 IP 地址
    LeetCode 456. 132模式
    LeetCode 341. 扁平化嵌套列表迭代器
    LeetCode 73. 矩阵置零
    LeetCode 47. 全排列 II
    LeetCode 46. 全排列
  • 原文地址:https://www.cnblogs.com/xing901022/p/5281769.html
Copyright © 2011-2022 走看看