-- 利用collapse和cardinality进行单字段去重https://blog.csdn.net/qq_43564245/article/details/128554317
GET /bank/_search
{
"query": {
"match_phrase": {
"address":"mill"
}
},
"sort": [
{
"account_number": "desc"
},
{
"balance": "asc"
}
],
"collapse": {
"field": "state.keyword"
},
"track_total_hits": true,
"aggs": {
"courseAgg": {
"cardinality": {
"field": "state.keyword"
}
}
}
}
第一次根据state去重
-- 多个字段去重
GET /bank/_search
{
"query": {
"match_phrase": {
"address": "mill"
}
},
"sort": [
{
"account_number": "desc"
},
{
"balance": "asc"
}
],
"aggs": {
"uv": {
"cardinality": {
"script": "doc['state.keyword'].value + '#' + doc['firstname.keyword'].value"
}
}
}
}