ES 索引

创建索引

对比关系型数据库,创建索引就等同于创建数据库。

需要记住的是,创建索引需要使用 PUT 请求方式,且该类型的请求是幂等的,也就意味着,无法多次创建相同名称的索引!

创建一个名称为 test_index 的索引:

# 在 kibana 的 Dev Tools 对话框里,只需要这么写,就可以创建该索引了
PUT test_index

# 返回:
{
 # 响应结果
 "acknowledged" : true,
 # 分片结果
 "shards_acknowledged" : true,
 # 索引名称
 "index" : "test_index"
}

# 如果重复添加索引,会返回错误信息 
{
 "error" : {
 "root_cause" : [
 {
 "type" : "resource_already_exists_exception",
 "reason" : "index [test_index/c6nJovSRSjSTTkpIgFy4-g] already exists",
 "index_uuid" : "c6nJovSRSjSTTkpIgFy4-g",
 "index" : "test_index"
 }
 ],
 "type" : "resource_already_exists_exception",
 "reason" : "index [test_index/c6nJovSRSjSTTkpIgFy4-g] already exists",
 "index_uuid" : "c6nJovSRSjSTTkpIgFy4-g",
 "index" : "test_index"
 },
 "status" : 400
}

题外话,使用 PostMan工具或者在 Head插件上都是可以正常操作的(后续都在 kibana中操作演示)。如:

# 选择 PUT请求方式
http:192.168.137.223:9200/test_index

查看索引

可以 Elasticsearch Head插件页面上看到:

es head插件.png

也可以向 ES 服务器发 GET 请求,查看索引信息:

# 查看指定名称的索引,如 test_index
GET test_index

# 结果为
{
 # 索引名
 "test_index" : {
 # 别名
 "aliases" : { },
 # 映射
 "mappings" : { },
 # 设置
 "settings" : {
 # 设置 - 索引
 "index" : {
 "routing" : {
 "allocation" : {
 "include" : {
 "_tier_preference" : "data_content"
 }
 }
 },
 # 设置 - 索引 - 主分片数量
 "number_of_shards" : "1",
 # 设置 - 索引 - 名称
 "provided_name" : "test_index",
 # 设置 - 索引 - 创建时间
 "creation_date" : "1621175229003",
 # 设置 - 索引 - 副分片数量
 "number_of_replicas" : "1",
 设置 - 索引 - 编号
 "uuid" : "bRJGP3RSQIaYxqLxmZRkYg",
 # 设置 - 索引 - 版本
 "version" : {
 "created" : "7120099"
 }
 }
 }
 }
}

# 查看 ES下所有的索引,_cat 表示查看的意思,indices 表示索引
GET _cat/indices?v

# 结果为
health status index      uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   test_index bRJGP3RSQIaYxqLxmZRkYg   1   1          0            0       208b           208b

上述查看所有索引返回的列表具体含义是:

表头 含义
health 当前服务器健康状态: green(集群完整), yellow(单点正常、集群不完整), red(单点不正常)
status 索引打开、关闭状态
index 索引名
uuid 索引统一编号
pri 主分片数量
rep 副本数量
docs.count 可用文档数量
docs.deleted 文档删除状态(逻辑删除)
store.size 主分片和副分片整体占空间大小
pri.store.size 主分片占空间大小

删除索引

删除索引也很简单,遵循 RestFul风格,只需要将请求类型改为 DELETE 即可。

DELETE test_index</pre>

示例,创建一个索引:

curl -XPUT 'http://10.123.7.3:9200/test_index' -H 'Content-Type: application/json' -d '{
 "settings": {
 "index": {
 "number_of_shards": "5",
 "number_of_replicas": "1",
 "max_result_window" :"60000"
 }
 },
 "mappings": {
 "wellenRoute": {
 "properties": {
 "wellenId": {
 "type": "integer"
 },
 "wellenCode": {
 "type": "keyword"
 },
 "nationalLineType": {
 "type": "integer"
 },
 "wellenType": {
 "type": "integer"
 },
 "wellenStatus": {
 "type": "integer"
 },
 "issueTime": {
 "type": "date",
 "format": "yyyy-MM-dd HH:mm:ss||epoch_millis"
 },
 "issueUser": {
 "type": "keyword"
 },
 "pickType": {
 "type": "integer"
 },
 "priorityLevel": {
 "type": "integer"
 },
 "operatorGroupName": {
 "type": "keyword"
 },
 "batchNum": {
 "type": "integer",
 "index": false
 },
 "packageNum": {
 "type": "integer",
 "index": false
 },
 "taskNum": {
 "type": "long",
 "index": false
 },
 "shouldPickNum": {
 "type": "long",
 "index": false
 },
 "realPickNum": {
 "type": "long",
 "index": false
 },
 "isCombine": {
 "type": "boolean"
 },
 "packType": {
 "type": "boolean"
 },
 "combineWellenType": {
 "type": "keyword"
 },
 "combineAddress": {
 "type": "integer"
 },
 "wellenMark": {
 "type": "integer"
 },
 "wellenMarkStr": {
 "type": "keyword"
 },
 "downwindAreaId": {
 "type": "integer"
 },
 "collectTips": {
 "type": "keyword"
 },
 "isAbc": {
 "type": "integer"
 },
 "wellenConfigId": {
 "type": "integer"
 },
 "wellenConfigName": {
 "type": "keyword"
 },
 "coWellenCode": {
 "type": "keyword"
 },
 "warehouseId": {
 "type": "integer"
 },
 "subWarehouseIdList": {
 "type": "integer",
 "fields": {
 "keyword": {
 "ignore_above": 256,
 "type": "keyword"
 }
 }
 },
 "createTime": {
 "type": "date",
 "format": "yyyy-MM-dd HH:mm:ss||epoch_millis"
 },
 "lastUpdateTime": {
 "type": "date",
 "format": "yyyy-MM-dd HH:mm:ss||epoch_millis"
 },
 "packageLabelNumMark": {
 "type": "boolean"
 },
 "createType": {
 "type": "integer"
 },
 "mainCollectionUser": {
 "type": "keyword"
 },
 "mainCollectionTime": {
 "type": "date",
 "format": "yyyy-MM-dd HH:mm:ss||epoch_millis"
 },
 "firstSowingStartTime": {
 "type": "date",
 "format": "yyyy-MM-dd HH:mm:ss||epoch_millis"
 },
 "firstSowingEndTime": {
 "type": "date",
 "format": "yyyy-MM-dd HH:mm:ss||epoch_millis"
 },
 "secondSowingStartTime": {
 "type": "date",
 "format": "yyyy-MM-dd HH:mm:ss||epoch_millis"
 },
 "secondSowingEndTime": {
 "type": "date",
 "format": "yyyy-MM-dd HH:mm:ss||epoch_millis"
 },
 "firstSowingUserName": {
 "type": "keyword"
 },
 "operateSubWarehouseId": {
 "type": "integer"
 },
 "areaId": {
 "type": "keyword"
 },
 "isDelete": {
 "type": "boolean"
 },
 "paramIntegerOne": {
 "type": "integer"
 },
 "paramIntegerTwo": {
 "type": "integer"
 },
 "paramLongOne": {
 "type": "long"
 },
 "paramLongTwo": {
 "type": "long"
 },
 "paramStringOne": {
 "type": "keyword"
 },
 "paramStringTwo": {
 "type": "keyword"
 },
 "paramStringThree": {
 "type": "keyword"
 },
 "paramStringFour": {
 "type": "keyword"
 },
 "paramDateOne": {
 "type": "date",
 "format": "yyyy-MM-dd HH:mm:ss||epoch_millis"
 },
 "paramDateTwo": {
 "type": "date",
 "format": "yyyy-MM-dd HH:mm:ss||epoch_millis"
 }
 }
 }
 }
}'
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,496评论 6 501
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,407评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,632评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,180评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,198评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,165评论 1 299
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,052评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,910评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,324评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,542评论 2 332
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,711评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,424评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,017评论 3 326
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,668评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,823评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,722评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,611评论 2 353

推荐阅读更多精彩内容

  • Elasticsearch 7.x 简介 Elasticsearch是一个开源,基于Apache Lucene库构...
    方穹轩阅读 1,821评论 1 4
  • The Elastic Stack,包括 Elasticsearch、Kibana、Beats 和 Logstas...
    dev_winner阅读 1,524评论 0 12
  • 前言 DSL全称 Domain Specific language,即特定领域专用语言 1.全局操作 1.1 查询...
    Rex_2013阅读 644评论 0 0
  • 智慧小区安全防护系统 一.实训背景 1、智慧小区工作需求各类小区分布在城市的各个⾓落,多构成单个或多个独立的区域,...
    晊恦_dc80阅读 117评论 0 0
  • 一.实训背景 1、智慧小区工作需求 各类小区分布在城市的各个⾓落,多构成单个或多个独立的区域,而这使得小区的管理更...
    cholesteroler阅读 128评论 0 0