1、根据条件修改的命令示例:
POST test1/_update_by_query
{ "query": { "term": { "phone": "12345678909" } } , "script": { "source": "ctx._source['message'] = 'xuwujing'" } }2、根据条件删除数据的命令示例: POST test/_delete_by_query
{ "query": { "term": { "phone": "12345678909" } } }3、删除字段数据的命令示例:
POST test/_doc/_update_by_query
{ "script":{ "lang":"painless", "inline":"ctx._source.remove(\"msgcode\")" } }4、查询所有 GET _search
{ "query": { "match_all": {} } }5、等值(term)查询
GET test1/_doc/_search
{ "query": { "term": { "phone": "12345678909" } } }6、一个字段匹配多个值 GET test1/_doc/_search
{ "query": { "terms": { "uid": [ 1234, 12345, 123456 ] } } }7、范围(range )查询 GET test1/_doc/_search
{ "query": { "range": { "uid": { "gt": 1234, "lte": 12345 } } } }8、存在(exists)查询 GET test1/_doc/_search
{ "query": { "exists": { "field":"msgcode" } } }9、组合(bool)查询 bool 可以用来合并多个过滤条件查询结果的布尔逻辑,它包含这如下几个操作符:
must : 多个查询条件的完全匹配,相当于 and。 must_not ::多个查询条件的相反匹配,相当于 not。 should : 至少有一个查询条件匹配, 相当于 or。
GET /test1/_search
{ "query": { "bool": { "must": { "term": { "phone": "12345678909" } }, "must_not": { "term": { "uid": 12345 } }, "should": [ { "term": { "uid": 1234 } }, { "term": { "uid": 123456 } } ], "adjust_pure_negative": true, "boost": 1 } } }10、模糊(wildcard)查询 GET /test1/_search
{ "query": { "wildcard": { "message":"*wu*" } } }11、正则(regexp)查询 GET /test1/_search
{ "query": { "regexp": { "message":"xu[0-9]" } } }