ES 各种查询方法【笔记】
作者:互联网
##全文检索匹配查询,按照评分排序,模糊查询
GET bank/_search
{
"query": {
"match": {
"address": "Kings"
}
}
}
##全文检索匹配查询,按照评分排序,短语匹配
GET bank/_search
{
"query": {
"match_phrase": {
"address": "Kings hwy"
}
}
}
## 多字段查询,模糊查询,或的关系,query是查询条件,fields是字段
GET bank/_search
{
"query": {
"multi_match": {
"query": "mill movico",
"fields": ["address","city"]
}
}
}
## filter 过滤条件,.keyword 精确查询
GET bank/_search
{
"query": {
"bool": {
"must": [
{"range": {
"age": {
"gte": 18,
"lte": 30
}
}}
],
"should": [
{"match": {
"gender.keyword": "F"
}}
],
"filter": [
{"range": {
"age": {
"gte": 22,
"lte": 30
}
}}
]
}
}
}
## 精确查询
GET bank/_search
{
"query": {
"term": {
"age": {
"value": "22"
}
}
}
}## aggs 聚合,aggsName 聚合名,terms 聚合类型 ,size 分页数为0输出
GET bank/_search
{
"query": {
"match": {
"address": "mill"
}
},
"aggs": {
"aggsName": {
"terms": {
"field": "age",
"size": 10
}
},
"aggAvg": {
"avg": {
"field": "age"
}
},
"banlance":{
"avg": {
"field": "balance"
}
}
},
"size": 0
}
## 按照年龄分布计算平均薪资,子聚合
GET bank/_search
{
"query": {
"match_all": {}
},
"aggs": {
"ageAggs": {
"terms": {
"field": "age",
"size": 100
},
"aggs": {
"balanceAvg": {
"avg": {
"field": "balance"
}
}
}
}
},
"size": 0
}
标签:search,GET,##,age,查询方法,笔记,bank,query,ES 来源: https://www.cnblogs.com/lishilin-glut/p/16244927.html