Elasticsearch: Merge result of aggregation by bucket key

≡放荡痞女 提交于 2019-12-11 06:15:45

问题


I've indexed entities in Elasticsearch, which occur in my documents. The mapping for the entities looks like the following:

"Entities": {
        "properties": {
          "EntFrequency": {
            "type": "long"
          },
          "EntId": {
            "type": "long"
          },
          "EntType": {
            "type": "string",
            "analyzer": "english",
            "fields": {
              "raw": {
                "type": "string",
                "index": "not_analyzed"
              }
            }
          },
          "Entname": {
            "type": "string",
            "analyzer": "english",
            "fields": {
              "raw": {
                "type": "string",
                "index": "not_analyzed"
              }
            }
          }
        }
      },
 [...]

Furthermore, I use this aggregation query to determine the most-occurring entities:

GET cable/document/_search
{
  "size" :0,
  "query": { 
    "match_all": {}
  },
  "aggs" : { 
      "entities_agg" : { 
          "terms" : { 
            "field" : "Entities.EntId"              
            }
          }
      }
   }
}

Response

"buckets": [
    {
      "key": 323644,
      "doc_count": 231038
    },
[...]

However, some of those entity mentions refer to the same entity e.g. "USA" and "United States" and I do know their ids. How do I merge the buckets and the counts of these duplicates in ES?

I cannot use a client-side solution since there are too many entities and retrieving all of them and merging would be probably too slow for my application. The knowledge about duplicates is acquired through runtime. Thus, I cannot use this knowledge for the initial creation of my ES index.

Thanks for your help and comments!

来源:https://stackoverflow.com/questions/39850138/elasticsearch-merge-result-of-aggregation-by-bucket-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!