6

elasticsearch简单的CRUD操作

 2 years ago
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.
neoserver,ios ssh client

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

返回内容过滤

  1. 过滤_source
    GET /index/type/_search?_source=false
GET /index/type/_search
{
"query": {
"match_all": {}
},
"_source": false
}
  1. 过滤_source中的部分字段
    GET /index/type/_search?_source_include=key1,key2
GET /index/type/_search
{
"query": {
"match_all": {}
},
"_source": {
"include": ["key1","key2","key3.*"]
}
}
  1. 显示_source中的部分字段
    GET /index/type/_search?_source_exclude=key3
GET /index/type/_search
{
"query": {
"match_all": {}
},
"_source": {
"exclude": ["key3"]
}
}
  1. 只返回_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"
}
}
}
]
}
}
}

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK