//创建mapping
PUT /my_index
{
"mappings" : {
"_doc" : { // --------- _doc 为 改索引的 type
"properties" : {
"字段1" : {
"type" : "keyword"
},
"字段2" : {
"type" : "double"
},
"字段3" : {
"type" : "integer"
} ,
"字段4" : {
"type" : "date",
"format" : "yyyy-MM-dd HH:mm:ss||epoch_millis||yyyy-MM-dd"
},
"字段5" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
},
"analyzer" : "whitespace",
"fielddata" : true
}
}
}
}
}
//创建完mapping后,新增字段
PUT my_index/_mappings/_doc
{
"properties": {
"新增字段1": {
"type": "keyword"
}
}
}
//更新某个字段的值
POST my_index/_doc/_id/_update
{
"doc" : {
"字段1" : "值1"
}
}
//创建完mapping后,删除某字段,可以用于创建mapping是字段类型错了,先删后增(没有数据的情况下)
//这个应该不对,只能删除某一个文档中的那个字段值
POST my_index/_doc/id/_update
{
"script" : "ctx._source.remove('要删除的字段1')"
}
//接上个,如果有数据,可以建一个新的索引,然后将原表数据 写入 新表
POST _reindex
{
"source": {
"index": "my_index"
},
"dest": {
"index": "my_index_new"
}
}
//查看mapping
GET my_index/_mapping/
//删除索引
DELETE my_index
//插入数据
POST my_index/my_type/1 -------// 1 为数据 id
{
"字段1" : "111",
"字段2" : "222"
}
//查询(简单)
GET my_index/_doc/_search
{
"query": {
"term":{
"字段1":"值1"
}
}
}
//删除某条数据
POST my_index/_doc/_delete_by_query
{
"query": {
"term":{
"字段1":"值1"
}
}
}
//删除所有数据
POST my_index/_delete_by_query?pretty
{
"query": {
"match_all": {
}
}
}