博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Elasticsearch 7.x:2、索引管理
阅读量:2388 次
发布时间:2019-05-10

本文共 5320 字,大约阅读时间需要 17 分钟。

2.1 索引名规范

索引命名有如下限制:

  • 仅限小写字母
  • 不能包含\/*?"<>|、#以及空格符等特殊符号
  • 从7.0版本开始不再包含冒号
  • 不能以-_+开头
  • 不能超过255个字节(注意它是字节,因此多字节字符将计入255个限制)

2.2 新建索引

(1)索引名小写

PUT test
{  "acknowledged" : true,  "shards_acknowledged" : true,  "index" : "test"}

在这里插入图片描述

(2)索引名不能包含大些字母

PUT Blog

相应结果:

{  "error": {    "root_cause": [      {        "type": "invalid_index_name_exception",        "reason": "Invalid index name [Blog], must be lowercase",        "index_uuid": "_na_",        "index": "Blog"      }    ],    "type": "invalid_index_name_exception",    "reason": "Invalid index name [Blog], must be lowercase",    "index_uuid": "_na_",    "index": "Blog"  },  "status": 400}

(3)重复创建索引

PUT test

相应结果:

{  "error": {    "root_cause": [      {        "type": "resource_already_exists_exception",        "reason": "index [test/XBKm9hVxSQGP6KTncA10WA] already exists",        "index_uuid": "XBKm9hVxSQGP6KTncA10WA",        "index": "test"      }    ],    "type": "resource_already_exists_exception",    "reason": "index [test/XBKm9hVxSQGP6KTncA10WA] already exists",    "index_uuid": "XBKm9hVxSQGP6KTncA10WA",    "index": "test"  },  "status": 400}

2.3 索引配置

创建索引时,可以制定相关设置,比如设置索引的分片数number_of_shards和副本数number_of_replicas

PUT blog{    "settings" : {        "index" : {            "number_of_shards" : 2,            "number_of_replicas" : 2        }    }}

也可以简化为

PUT blog{    "settings" : {        "number_of_shards" : 2,        "number_of_replicas" : 2    }}

也就是说,不必在settings部分中明确指定索引部分。

相应结果:

{  "acknowledged" : true,  "shards_acknowledged" : true,  "index" : "blog"}

2.4 查看索引

(1)查看制定索引

GET blog

相应结果:

{  "blog" : {    "aliases" : { },    "mappings" : { },    "settings" : {      "index" : {        "creation_date" : "1547012455291",        "number_of_shards" : "2",        "number_of_replicas" : "2",        "uuid" : "RorVlzACQIOpGDCW9LJ1cA",        "version" : {          "created" : "6050499"        },        "provided_name" : "blog"      }    }  }}

(2)查看索引列表

GET /_cat/indices?v

相应结果如下,可以看到两个刚刚创建的索引,.kibana_1是Kibana自带样例索引。

health status index     uuid                   pri rep docs.count docs.deleted store.size pri.store.sizeyellow open   blog      RorVlzACQIOpGDCW9LJ1cA   2   2          0            0       522b           522bgreen  open   .kibana_1 vfaeT7wQSgyxXOlZioCFDQ   1   0          3            0     11.9kb         11.9kbyellow open   test      k4WAeNOqSpGzQbO3euWy2w   1   1          0            0       230b           230b

需要注意:我们新建的索引,默认分片和副本都是1。

(3)判定索引是否存在

HEAD blog

相应结果:

200 - OK

2.5 更新副本数

PUT blog/_settings{  "number_of_replicas": 1}

相应结果:

{  "acknowledged" : true}

2.6 查看索引配置信息

GET blog/_settings

相应结果:

{  "blog" : {    "settings" : {      "index" : {        "creation_date" : "1547012455291",        "number_of_shards" : "2",        "number_of_replicas" : "1",        "uuid" : "RorVlzACQIOpGDCW9LJ1cA",        "version" : {          "created" : "6050499"        },        "provided_name" : "blog"      }    }  }}

2.7 删除索引

可以直接使用DELETE命令删除索引

DELETE test

相应结果:

{  "acknowledged" : true}

2.8 索引的关闭与打开

一个关闭的索引几乎不占用系统资源。我们可以临时关闭某个索引,在需要时再重新打开该索引。

(1)关闭blog

POST blog/_close

相应结果:

{  "acknowledged" : true}

(2)查看索引

GET /_cat/indices?v

相应结果:

health status index     uuid                   pri rep docs.count docs.deleted store.size pri.store.size       close  blog      RorVlzACQIOpGDCW9LJ1cA                                                          green  open   .kibana_1 vfaeT7wQSgyxXOlZioCFDQ   1   0          3            0     11.9kb         11.9kb

(3)重新打开blog

POST blog/_open

相应结果:

{  "acknowledged" : true,  "shards_acknowledged" : true}

2.9 指定type的mapping

创新索引时,允许提供一个type的映射。

创新创建索引test,并制定默认_doc类型的mappings

PUT test{    "settings" : {        "number_of_shards" : 1    },    "mappings" : {        "_doc" : {            "properties" : {                "field1" : { "type" : "text" }            }        }    }}

相应结果:

{  "acknowledged" : true,  "shards_acknowledged" : true,  "index" : "test"}

2.10 索引别名

索引别名不仅仅可以关联一个索引,它能聚合多个索引。此外,一个别名也可以与一个过滤器相关联, 这个过滤器在搜索和路由的时候被自动应用。

(1)创建多个索引

PUT index1PUT index2

(2)创建index1的别名alias1

POST _aliases{  "actions": [    {      "add": {        "index": "index1",        "alias": "alias1"      }    }  ]}
{  "acknowledged" : true}

说明:此时别名alias1和index1一对一。

(3)添加多个索引的别名

POST _aliases{  "actions": [    {      "add": {        "indices": ["index2","test"],        "alias": "alias1"      }    }  ]}
{  "acknowledged" : true}

说明:我们是不能对alias1进行写操作,当有多个索引时的别名,不能区分到底操作哪一个索引。

(4)移除别名

POST _aliases{  "actions": [    {      "remove": {        "index": "test",        "alias": "alias1"      }    }  ]}
{  "acknowledged" : true}

(5)查看别名

GET alias1
{  "index1" : {    "aliases" : {      "alias1" : { }    },    "mappings" : { },    "settings" : {      "index" : {        "creation_date" : "1547013859010",        "number_of_shards" : "1",        "number_of_replicas" : "1",        "uuid" : "sbbArnOvTYqf07rXlTpFtA",        "version" : {          "created" : "6050499"        },        "provided_name" : "index1"      }    }  },  "index2" : {    "aliases" : {      "alias1" : { }    },    "mappings" : { },    "settings" : {      "index" : {        "creation_date" : "1547013863297",        "number_of_shards" : "1",        "number_of_replicas" : "1",        "uuid" : "qqRkUXOcQfuBTf1eBqvMPA",        "version" : {          "created" : "6050499"        },        "provided_name" : "index2"      }    }  }}

转载地址:http://mrvab.baihongyu.com/

你可能感兴趣的文章
tomcat RequestDispatcher directory traversal vulnerability
查看>>
Apache Tomcat information disclosure vulnerability
查看>>
MySQL 'sql_parse.cc' Multiple Format String Vulnerabilities
查看>>
canvas and core impact中国购买地址
查看>>
mysql+php搜索型注入问题记录
查看>>
Windows7 64位下搭建PyGTK开发环境
查看>>
ajax XMLHttpRequest五步使用法
查看>>
ajax跨域和js跨域解决方案 .
查看>>
如何用Squid来实现Ajax跨域代理
查看>>
APEX的安装
查看>>
Metasploit和armitage整合教程
查看>>
使用安全json parser防止json注入
查看>>
所有从非官方网站下载的putty和WinSCP都有后门(附清理方式)
查看>>
PHP 5.2.12 / 5.3.1 safe_mode / open_basedir Bypass
查看>>
Metasploit攻击Oracle的环境搭建
查看>>
信息安全合规性产品
查看>>
google-gruyere web2.0漏洞学习平台 =w=~
查看>>
Preventing Cross-site Scripting Attacks
查看>>
WASC Distributed Web Honeypots Project Update
查看>>
安装pydev到eclipse
查看>>