groupby查询后在存储桶上增加MergeID?

时间:2019-07-10 13:32:28

标签: elasticsearch

我想执行一个groupby查询,并让该存储桶中的每个记录的每个“存储桶”具有相同的MergeID-但该存储桶的mergeID应该是唯一的。只需增加某种变量即可完成此操作,但我不确定该怎么做。

GET /custdata-duprecords/_search? 
{ 
    "size": 0, 
    "aggs": { 
        "GroupByType": { 
            "terms": { 
                "field": "Email.keyword", 
                "size": 15 
            }, 
            "aggs": { 
                "Group": { 
                    "top_hits": { 
                        "size": 2, 
                        "_source": { 
                            "includes": [ 
                                "Email", 
                                "CustomerNo", 
                                "FirstName", 
                                "LastName", 
                                "Phone" 
                            ] 
                        }, 
                        "sort": [ 
                            { 
                                "CustomerNo.keyword": { 
                                    "order": "asc" 
                                } 
                            } 
                        ] 
                    } 
                } 
            } 
        } 
    } 
} 

有关如何返回“存储桶”的信息,请参见下文。

{
          "key" : "## *GENERIC* ## ",
          "doc_count" : 1,
          "Group" : {
            "hits" : {
              "total" : {
                "value" : 1,
                "relation" : "eq"
              },
              "max_score" : null,
              "hits" : [
                {
                  "_index" : "custdata-10k",
                  "_type" : "cust",
                  "_id" : "250",
                  "_score" : null,
                  "_source" : {
                    "Email" : "## *GENERIC*",
                    "FirstName" : ":FIRST",
                    "Phone" : null,
                    "LastName" : "LAST",
                    "CustomerNo" : null
                  },
                  "sort" : [
                    null
                  ]
                }
              ]
            }
          }
        },
{
          "key" : "email@email.com ",
          "doc_count" : 1,
          "Group" : {
            "hits" : {
              "total" : {
                "value" : 1,
                "relation" : "eq"
              },
              "max_score" : null,
              "hits" : [
                {
                  "_index" : "custdata-10k",
                  "_type" : "cust",
                  "_id" : "253",
                  "_score" : null,
                  "_source" : {
                    "Email" : "email@email.com",
                    "FirstName" : ":email",
                    "Phone" : 8987737717,
                    "LastName" : "email",
                    "CustomerNo" : 989367
                  },
                  "sort" : [
                    null
                  ]
                }
              ]
            }
          }
        }

0 个答案:

没有答案