ElasticSearch笔记-索引操作

查看索引信息

GET index1

查看索引配置信息

GET index1/_setting

查看索引映射信息

GET index1/_mapping

创建索引

PUT index1
{
	"settings": {
		"number_of_shards": 3,
		"number_of_replicas": 2
	},
	"mappings": {
			"properties": {
				"commodity_id": {
					"type": "long"
				},
				"commodity_name": {
					"type": "text"
				},
				"picture_url": {
					"type": "keyword"
				},
				"price": {
					"type": "double"
				}
			}
		}
}

number_of_shards:
number_of_replicas:副本数

向已创建的索引中添加字段

PUT abc/_mapping
{
"properties": {
"commodity_id": {
"type": "long"
},
"commodity_name": {
"type": "text"
},
"picture_url": {
"type": "keyword"
},
"price": {
"type": "double"
}
}
}

关闭索引

如果索引被关闭,那么关于这个索引的所有读写操作都会被阻断

POST index1/_close

打开索引

POST index1/_open

冻结索引

冻结索引和关闭索引类似,关闭索引是既不能读,也不能写。而冻结索引是可以读,但是不能写

POST index1/_freeze

解冻索引

POST index1/_unfreeze

删除索引:

DELETE index1 

在多个索引库中执行操作

GET index1,index2,index3/_search
GET index1,index2,index3/_mapping

查看集群状态

GET _cat/health?v

动态映射

通常情况下,我们使用ES建立索引的步骤是,先创建索引,然后定义索引中的字段以及映射的类型,然后再向索引中导入数据。而动态映射可以直接向文档中导入一条数据,与此同时,索引、字段、字段类型都会自动创建,无需你做其他的操作。这就是动态映射
动态字段映射

JSON数据类型 ES数据类型
true 或 false boolean类型
浮点型数字 float
整型数字 long
JSON对象 Object
数组 第一个非空值得类型
String 1、如果满足日期类型的格式,映射为日期类型
2、如果满足数字型的格式,映射为long或者float
3、如果就是字符串,会映射为一个text类型和一个keyword类型
原文地址:https://www.cnblogs.com/fanfan-90/p/14169954.html