首页 > 其他分享 >ES多字段去重

ES多字段去重

时间:2023-03-19 15:12:50浏览次数:28  
标签:多字 keyword number state query phrase cardinality ES

-- 利用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"
      }
    }
  }
}

第二次根据state和firstname去重

标签:多字,keyword,number,state,query,phrase,cardinality,ES
From: https://www.cnblogs.com/SimonHu1993/p/17233268.html

相关文章