elasticsearch简单的CRUD操作
祈雨的笔记
·
2018-09-09
·
via 祈雨的笔记
create
1 2 3 4
| PUT /index/type/id { "key":"value" }
|
例如:
1 2 3 4 5 6 7
| PUT /ecommerce/product/1 { "name":"高露洁牙膏", "desc":"高效美白", "price":30, "tags":["美白","防蛀"] }
|
delete
例如:
1
| DELETE /ecommerce/product/1
|
update
1 2 3 4 5 6
| POST /index/type/id/_update { "doc": { "key":"value" } }
|
例如:
1 2 3 4 5 6
| POST /ecommerce/product/1/_update { "doc": { "name":"佳洁士牙膏" } }
|
read
例如:
1
| GET /ecommerce/product/1
|
返回内容过滤
- 过滤
_source1
| GET /index/type/_search?_source=false
|
1 2 3 4 5 6 7
| GET /index/type/_search { "query": { "match_all": {} }, "_source": false }
|
- 过滤
_source中的部分字段1
| GET /index/type/_search?_source_include=key1,key2
|
1 2 3 4 5 6 7 8 9
| GET /index/type/_search { "query": { "match_all": {} }, "_source": { "include": ["key1","key2","key3.*"] } }
|
- 显示
_source中的部分字段1
| GET /index/type/_search?_source_exclude=key3
|
1 2 3 4 5 6 7 8 9
| GET /index/type/_search { "query": { "match_all": {} }, "_source": { "exclude": ["key3"] } }
|
- 只返回
_source1
| GET /index/type/id/_source
|
script
例如:
1 2 3 4 5 6 7
| POST /ecommerce/product/1/_update { "script": { "params": {"count":2}, "inline": "ctx._source.price += params.count" } }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| GET /ecommerce/product/_search { "query": { "bool": { "must": [ { "script":{ "script":{ "params": {"count":36}, "inline": "doc.price.value == params.count" } } } ] } } }
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。