- match_all 查询所有
GET test/_search
{
"query": {
"match_all": {}
}
}
- match 单字段匹配查询
GET test/_search
{
"query":{
"match":{
"name":"zhangsan"
}
}
}
- multi_match 多字段匹配查询
GET test/_search
{
"query":{
"match":{
"name":"zhangsan"
}
}
}
- term 关键字精确查询
GET test/_search
{
"query": {
"term": {
"name": {
"value": "zhangsan"
}
}
}
}
- terms 多关键字精确查询
GET test/_search
{
"query": {
"terms": {
"status": {
"value": [0,1,2,3]
}
}
}
}
- fuzzy 模糊匹配选择展示指定字段
GET test/_search
{
"query": {
"fuzzy": {
"data": "好"
}
},
"_source": ["name", "data"]
}
- 过滤字段
- includes:来指定想要显示的字段
- excludes:来指定不想要显示的字段
GET test/_search
{
"query": {
"terms": {
"nickname": ["zhangsan"]
}
},
"_source": {
"includes": ["name","nickname"
]
}
}
- exists 查询字段age存在且id等于45的数据
GET /test/_search
{
"query": {
"bool": {
"must": [
{
"exists": {
"field": "age"
}
},
{
"term": {
"id": {
"value": 45
}
}
}
]
}
}
}
- 组合查询 排序+分页
GET /test/_search
{
"query": {
"bool": {
"must": [
{
"terms": {
"is_success": [1,2]
}
},
{
"term": {
"deleted": 0
}
}
]
}
},
"_source": ["_id","name","stage"],
"sort": [
{
"customer_gmt_create_time": {
"order": "asc"
}
}
],
"from": 0,
"size": 10
}
- match_phrase_prefix 前缀查询
GET test/_search
{
"query": {
"match_phrase_prefix": {
"name": "wang"
}
}
}
- 指定id批量查询
GET test/_search
{
"query": {
"ids": {
"values": ["66606794","66606795"]
}
}
}
- 组合查询(range+should)
GET test/_search
{
"query": {
"bool": {
"must": [
{
"range": {
"create_time": {
"gte": "2017-12-25 01:25:10",
"lte": "2017-12-25 12:10:36"
}
}
},
{
"bool": {
"should": [
{
"term": {
"name": {
"value": "zhangsan"
}
}
},
{
"term": {
"age": {
"value": 7
}
}
}
]
}
}
]
}
},
"_source": ["alarm_name","alarm_time","alarm_type","info"],
"sort": [
{
"customer_gmt_create_time": {
"order": "asc"
}
}
],
"from": 0,
"size": 10
}
文章来源地址https://www.toymoban.com/news/detail-411641.html
文章来源:https://www.toymoban.com/news/detail-411641.html
到了这里,关于elasticsearch 查询语法的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!