eleastcsearch01-操作mapping
作者:互联网
# ElasticSearch version "number": "7.14.1"
# 获取健康值
GET _cat/health?v
# 获取所有的信息
GET _cat/indices?v
# mappings信息=======================================
# 创建test3索引
# mapping number_of_shards分片数
# number_of_replicas版本数
PUT /test3
{
"settings":{
"number_of_shards":1,
"number_of_replicas":0
},
"mappings":{
"properties":{
"pushTime":{
"type":"long"
}
}
}
}
# 获取mapping信息
GET test3
# 获取 mapping信息
GET /test3/_mapping?pretty
# 给test3新增一个skuNumber字段,执行下面的命令即可修改mapping。
PUT /test3/_mapping
{
"properties":{
"skuNumber1":{
"type":"keyword"
}
}
}
# 新增记录
put test3/_doc/1
{
"skuNumber1":"1122-3344"
}
GET test3/_doc/1
# 新增pushTime字段后,历史数据是没有默认值的。
# 场景一:因为es索引结构特性,当我们对现有索引新增字段时,历史数据并不会有默认值
# 场景二:新增记录时,如果没有写入这个字段值时,也不会有默认值
# 所以有时我们需要给历史数据设置认值,
# 设置默认值时,如果历史数据的此字段已经有值,不会被修改,只会对无值的数据进行修改。
# 设置默认值后,再写入数据新数据,如果此字段没有给值,依然会是null值
# 以命令为指定type类型为_doc的记录 修改默认值为1332466578
POST test3/_doc/_update_by_query
{
"script": {
"lang": "painless",
"source": "if (ctx._source.pushTime== null) {ctx._source.pushTime= 1332466578}"
}
}
# 时间类型
PUT /test2
{
"mappings": {
"properties": {
"date": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd ||HH:mm:ss ||epoch_millis"
}
}
}
}
POST _bulk
{"index":{"_index":"test2","_type":"_doc","_id":1}}
{ "date": "2022-01-02" }
{"index":{"_index":"test2","_type":"_doc","_id":2}}
{ "date": "12:00:00" }
{"index":{"_index":"test2","_type":"_doc","_id":3}}
{ "date": "1420070400001" }
{"index":{"_index":"test2","_type":"_doc","_id":4}}
{ "date": "2018-10-01 12:00:00" }
# delete mapping
DELETE /test2
//查所有信息 查所有索引
GET _search
{
"query": {
"match_all": {}
}
}
# 获取test2所有信息
GET /test2/_doc/_search
# 查所有信息 查索引kibana_sample_data_flights
GET /kibana_sample_data_flights/_search
{
"query": {
"match_all": {}
}
}
# 查所有信息 查多个索引,用逗号隔开
GET /test2,kibana_sample_data_flights/_search
{
"query": {
"match_all": {}
}
}
# 复杂数据类型
# es支持复杂的数据类型,包括:object、array、nested。用的不是很多,举个实例:
PUT /test4
{
"settings":{
"number_of_shards":1,
"number_of_replicas":0
},
"mappings":{
"properties":{
"manager":{
"properties":{
"age":{
"type":"long"
},
"name":{
"properties":{
"first":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
},
"last":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
}
}
}
}
},
"region":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
}
}
}
}
PUT /test4/_doc/1
{
"region": "US",
"manager": {
"age": 30,
"name": {
"first": "John",
"last": "Smith"
}
}
}
GET /test4/_mapping?pretty
GET /test4/_doc/1
DELETE /test4
#存储方式:
{
"region": "US",
"manager.age": 30,
"manager.name.first": "John",
"manager.name.last": "Smith"
}
更新数据类型参考:
https://blog.csdn.net/liuxiao723846/article/details/109099508
https://www.cnblogs.com/shoufeng/p/10692113.html
标签:eleastcsearch01,test3,test2,GET,doc,mapping,操作,type 来源: https://www.cnblogs.com/haima/p/16201395.html