根据条件查询
POST 索引/_search
{
"size": 2000,
"query": {
"match": {
"字段名": "值"
}
}
}
#例子:
POST xmall-goods/_search
{
"size": 1000,
"query": {
"bool":{
"must": [
{
"match": {
"marketable": "1"
}
},
{
"match": {
"state": "0"
}
},
{
"match": {
"delFlag": "0"
}
},
{
"match": {
"supplier.reviewStatus": "PASSED"
}
}
]
}
}
}
索引增加字段并设置默认值
PUT 索引/_mapping/
{
"properties": {
"字段":{
"type": "类型"
}
}
}
#例子:
PUT xmall-goods/_mapping/
{
"properties": {
"shippingType":{
"type": "long"
}
}
}
#查询出没有该字段的数据并赋值
POST 索引/_update_by_query
{
"script": {
"lang": "painless",
"source": "ctx._source.字段=默认值"
},
"query": {
"bool": {
"must_not": {
"exists": {
"field": "字段"
}
}
}
}
}
#例子
POST xmall-goods/_update_by_query
{
"script": {
"lang": "painless",
"source": "ctx._source.shippingType=1"
},
"query": {
"bool": {
"must_not": {
"exists": {
"field": "shippingType"
}
}
}
}
}
#如果数据量大可以这样
POST xmall-goods/_update_by_query?wait_for_completion=false
{
"script": {
"lang": "painless",
"source": "ctx._source.shippingType=1"
},
"query": {
"bool": {
"must_not": {
"exists": {
"field": "shippingType"
}
}
}
}
}
#返回task
{
"task" : "rCNF7Ot1RuyzOb9duVw4EQ:3570870"
}
#根据task查询是否完成
GET _tasks/rCNF7Ot1RuyzOb9duVw4EQ:3570870
#此处可以再通过查询校验一下是否真的完成
GET xmall-goods/_search
{
"query": {
"bool": {
"must_not": {
"exists": {
"field": "shippingType"
}
}
}
}
}
根据条件删除数据
#1.根据id删除
DELETE 索引/_doc/数据id
#2.根据其他查询条件删除
POST 索引/_delete_by_query
{
"query": {
"match": {
"字段": "值"
}
}
}