【ElasticSearch】添加、更新、删除索引和文档
======================================================================
索引
1、添加
2、更新
3、删除
4、关闭打开
文档
1、添加
2、更新
3、删除
======================================================================
索引
1、添加
PUT get-together { "settings": { "number_of_shards": 1, "number_of_replicas": 1 }, "mappings": { "properties": { "name": { "type": "text", "index": true } } } }
2、更新
PUT get-together/_mapping { "properties": { "age": { "type": "integer" } } }
3、删除
DELETE get-together
4、关闭打开
POST get-together/_close
POST get-together/_open
文档
1、添加
PUT get-together/_doc/1 { "name": "Jim Green", "age": 28 }
2、更新
更新部分文档(必须存在)
POST get-together/_update/1 { "doc": { "name": "Alice Smith" } }
upsert更新或添加文档
POST get-together/_update/2 { "doc": { "name": "Alice Smith" }, "upsert": { "name": "Alice Smith", "age": 0 } }
通过脚本更新文档
lang painless(默认),expression
POST get-together/_update/1 { "script": {
"lang": "painless", "source": "ctx._source.age = params.incnum", "params": { "incnum": 13 } } }
条件更新文档
POST get-together/_update_by_query { "query": { "bool": { "must": [ { "term": { "age": { "value": "28" } } } ] } }, "script": { "lang": "painless", "source": "ctx._source.name = params.newname", "params": { "newname": "this is new name" } } }
3、删除
删除单个文档
DELETE get-together/_doc/1
条件删除文档
POST get-together/_delete_by_query { "query": { "bool": { "must": [ { "term": { "age": { "value": 28 } } } ] } } }