数据查找
// 查找所有数据
GET 索引/类型/_search
{
"query": {
"match_all": {}
}
}
// 查找数据字段
GET /ecommerce/product/_search
{
"query": { "match_all": {} },
"_source": ["name", "price"]
}
// 查找具体某一条数据
GET 索引/_search
{
"query": {
"bool": {
"must": [
{
"term" : {
"spuBarcode" : {
"value" : "123456"
}
}
}
]
}
}
}
更新某一条数据
// 已知ID对数据进行更新
// 通常先使用search找到对应数据的id后再利用update更新
POST 索引/类型/id/_update
{
"doc": {
"更新字段名":"更新值"
}
}
// 搜索并更新数据
POST 索引/data/_update_by_query
{
"query": {
"bool": {
"must": [
{
"term" : {
"spubarcode" : {
"value" : "123456"
}
}
}
]
}
},
// "script" : "ctx._source" 是内部定义好的获取_source数据的方式,status是需要更新的字段
"script": "ctx._source.status='2'"
// 或者
"script": {
"source": "ctx._source.status='2'"
}
}