6
elasticsearch简单的CRUD操作
source link: https://wakzz.cn/2018/09/09/elasticsearch/%E7%AE%80%E5%8D%95%E7%9A%84CRUD%E6%93%8D%E4%BD%9C/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
elasticsearch简单的CRUD操作
祈雨的博客
2018-09-09
create
PUT /index/type/id
{
"key":"value"
}
PUT /ecommerce/product/1
{
"name":"高露洁牙膏",
"desc":"高效美白",
"price":30,
"tags":["美白","防蛀"]
}
delete
DELETE /index/type/id
DELETE /ecommerce/product/1
update
POST /index/type/id/_update
{
"doc": {
"key":"value"
}
}
POST /ecommerce/product/1/_update
{
"doc": {
"name":"佳洁士牙膏"
}
}
GET /index/type/id
GET /ecommerce/product/1
返回内容过滤
- 过滤
_source
GET /index/type/_search?_source=false
GET /index/type/_search
{
"query": {
"match_all": {}
},
"_source": false
}
- 过滤
_source
中的部分字段GET /index/type/_search?_source_include=key1,key2
GET /index/type/_search
{
"query": {
"match_all": {}
},
"_source": {
"include": ["key1","key2","key3.*"]
}
}
- 显示
_source
中的部分字段GET /index/type/_search?_source_exclude=key3
GET /index/type/_search
{
"query": {
"match_all": {}
},
"_source": {
"exclude": ["key3"]
}
}
- 只返回
_source
GET /index/type/id/_source
script
POST /ecommerce/product/1/_update
{
"script": {
"params": {"count":2},
"inline": "ctx._source.price += params.count"
}
}
GET /ecommerce/product/_search
{
"query": {
"bool": {
"must": [
{
"script":{
"script":{
"params": {"count":36},
"inline": "doc.price.value == params.count"
}
}
}
]
}
}
}
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK