//創(chuàng)建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
}
}
}
}
}
//創(chuàng)建完mapping后,新增字段
PUT my_index/_mappings/_doc
{
"properties": {
"新增字段1": {
"type": "keyword"
}
}
}
//更新某個字段的值
POST my_index/_doc/_id/_update
{
"doc" : {
"字段1" : "值1"
}
}
//創(chuàng)建完mapping后,刪除某字段,可以用于創(chuàng)建mapping是字段類型錯了,先刪后增(沒有數(shù)據(jù)的情況下)
//這個應該不對,只能刪除某一個文檔中的那個字段值
POST my_index/_doc/id/_update
{
"script" : "ctx._source.remove('要刪除的字段1')"
}
//接上個,如果有數(shù)據(jù),可以建一個新的索引,然后將原表數(shù)據(jù) 寫入 新表
POST _reindex
{
"source": {
"index": "my_index"
},
"dest": {
"index": "my_index_new"
}
}
//查看mapping
GET my_index/_mapping/
//刪除索引
DELETE my_index
//插入數(shù)據(jù)
POST my_index/my_type/1 -------// 1 為數(shù)據(jù) id
{
"字段1" : "111",
"字段2" : "222"
}
//查詢(簡單)
GET my_index/_doc/_search
{
"query": {
"term":{
"字段1":"值1"
}
}
}
//刪除某條數(shù)據(jù)
POST my_index/_doc/_delete_by_query
{
"query": {
"term":{
"字段1":"值1"
}
}
}
//刪除所有數(shù)據(jù)
POST my_index/_delete_by_query?pretty
{
"query": {
"match_all": {
}
}
}
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者