zoukankan      html  css  js  c++  java
  • Elasticsearch多索引

     在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来决定。

    好的代码像粥一样,都是用时间熬出来的
  • 相关阅读:
    Top 10 Product Manager Skills To Boost Your Resume In 2021
    大数据知识梳理
    B端产品如何设计权限系统?
    华三盒式交换机MAC、ARP、Route性能表项参数查询
    中了传说中的挖矿病毒
    SqlServer 2019 事务日志传送
    docker中生成的pdf中文是方框的解决方案
    The Live Editor is unable to run in the current system configuration
    2021 面试题大纲
    五分钟搞定Docker安装ElasticSearch
  • 原文地址:https://www.cnblogs.com/miqi1992/p/5468754.html
Copyright © 2011-2022 走看看