zoukankan      html  css  js  c++  java
  • Elasticsearch(009):es中index(索引)的新增、修改、删除、关闭等操作

    Elasticsearch(009):es中index(索引)的新增、修改、删除、关闭等操作
    原创瘦子没有夏天 发布于2020-01-03 18:31:38 阅读数 17  收藏
    展开
    文章目录
    索引(Index)
    1. 添加索引
    2. 获取索引
    3. 修改索引
    4. 删除索引
    5. 打开/关闭索引
    6. 获取所有索引列表
    索引(Index)
    本篇文章主要学习索引的相关操作。

    1. 添加索引
    PUT example
    {
        "settings" : {
            "index" : {
                "number_of_shards" : 2, #设置分片的数量,在集群中通常设置多个分片,表示一个索引库将拆分成多片分别存储不同的结点,提高了ES的处理能力和高可用性,这里设置为2。
                "number_of_replicas" : 1 #设置副本的数量,设置副本是为了提高ES的高可靠性,这里设置成设置为1
            }
        }
    }

    返回值

    {
      "acknowledged" : true, #表示创建成功
      "shards_acknowledged" : true,
      "index" : "example"
    }

    当然还有不止一个参数针对Index,更多的可以参考这里。 todo

    2. 获取索引
    GET example
    返回值

    {
      "example" : {
        "aliases" : { },
        "mappings" : { },
        "settings" : {
          "index" : {
            "creation_date" : "1573387465030",
            "number_of_shards" : "2",
            "number_of_replicas" : "1",
            "uuid" : "yw-ZmC4ATjeukZb6N-ub8A",
            "version" : {
              "created" : "6050499"
            },
            "provided_name" : "example"
          }
        }
      }
    }

    上面的示例获取名为的索引的信息example。需要指定索引,别名或通配符表达式。

    通过使用_all或*作为索引,get index API也可以应用于多个索引,或者应用于所有索引。

    3. 修改索引
    修改example索引的max_result_window的值,调大一些。默认是10000。使用ES的人肯定知道其分页在超过10000条数据后会报错。

    Result window is too large, from + size must be less than or equal to: [10000] but was [78020]. See the scroll api for a more efficient way to request large data sets. This limit can be set by changing the [index.max_result_window] index level setting.
    1
    所以这里我们以此为例来动态修改其值,来解决这个问题。

    PUT example/_settings
    {
      "index.max_result_window": 1000000000
    }

    返回结果

    {
      "acknowledged" : true
    }

    我们通过刚刚的查询方法,获取索引,来查看我们的修改操作是否已经生效。

    4. 删除索引
    DELETE example
    返回结果

    {
      "acknowledged" : true
    }

    这时我们通过查询索引方法就会报错。如下

    {
      "error" : {
        "root_cause" : [
          {
            "type" : "index_not_found_exception",
            "reason" : "no such index",
            "index_uuid" : "_na_",
            "resource.type" : "index_or_alias",
            "resource.id" : "example",
            "index" : "example"
          }
        ],
        "type" : "index_not_found_exception",
        "reason" : "no such index",
        "index_uuid" : "_na_",
        "resource.type" : "index_or_alias",
        "resource.id" : "example",
        "index" : "example"
      },
      "status" : 404
    }
    5. 打开/关闭索引
    打开和关闭索引API允许先关闭索引,然后再打开索引。封闭索引几乎没有集群开销(除了维护其元数据),并且被禁止进行读/写操作。可以打开一个封闭的索引,然后将通过正常的恢复过程。

    REST端点为/{index}/_close和/{index}/_open。例如

    #关闭索引
    POST /example/_close
    1
    2
    返回值

    {
      "acknowledged" : true
    }
    #打开索引
    POST /example/_open
    返回值

    {
      "acknowledged" : true,
      "shards_acknowledged" : true
    }
    6. 获取所有索引列表
    #获取所有索引列表
    GET _all
    其实创建索引时也可以同时创建映射,也可以后面添加创建。我们下一小节将研究映射的问题。
    ————————————————
    版权声明:本文为CSDN博主「瘦子没有夏天」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/weixin_39723544/article/details/103825051

  • 相关阅读:
    UE4 学习 噩梦项目
    字符串学习笔记
    luogu P4391 [BOI2009]Radio Transmission 无线传输
    luogu P2153 [SDOI2009]晨跑
    网络流学习笔记
    UVA437 【巴比伦塔 The Tower of Babylon】
    基础重修笔记
    luogu P1283 【平板涂色】
    树链剖分学习笔记
    DP学习笔记
  • 原文地址:https://www.cnblogs.com/grj001/p/12223019.html
Copyright © 2011-2022 走看看