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
}