Elasticsearch-选择具有特定计数的数据组

时间:2019-04-24 08:10:51

标签: elasticsearch

以下是我拥有的数据类型的示例:

enter image description here

如何在Elasticsearch中通过SQL查询实现类似以下的功能。我的结果必须包括实际数据,而不仅仅是满足我要求的文件数量:

SELECT firstName, secondName, Country, City, Street, postalCode, House, Phone, Fax, count(*) FROM my_bucket
WHERE Country = 'GBR'
GROUP BY firstName, secondName, Country, City, Street, postalCode, House, Phone, Fax
ORDER BY firstName, secondName, Country, City, Street, postalCode, House, Phone, Fax
HAVING count(*) > 1;

这是我尝试过的:

{
    "size" : 0,
    "query": {
      "bool": {
        "must": [
          {
            "term": {
            "Country": {
              "value": "GBR"
              }
            }
          }
        ]
      }
    }, 
    "aggs" : {
        "grouped_firstName" : {
            "terms" : {
                "field" : "firstName",
                "size" : 100000
            },
            "aggs": {
              "grouped_secondName": {
                "terms": {
                  "field": "secondName",
                  "size": 100000
                },
                "aggs": {
                  "grouped_Country": {
                    "terms": {
                      "field": "Country",
                      "size": 100000
                    },
                    "aggs": {
                      "grouped_City": {
                        "terms": {
                          "field": "City",
                          "size": 100000
                        },
                        "aggs": {
                          "grouped_Street": {
                            "terms": {
                              "field": "Street",
                              "size": 100000
                            },
                            "aggs": {
                              "grouped_postalCode": {
                                "terms": {
                                  "field": "postalCode",
                                  "size": 100000
                                },
                                "aggs": {
                                  "grouped_House": {
                                    "terms": {
                                      "field": "House",
                                      "size": 100000
                                    },
                                    "aggs": {
                                      "grouped_Phone": {
                                        "terms": {
                                          "field": "Phone",
                                          "size": 100000
                                        },
                                        "aggs": {
                                          "grouped_Fax": {
                                            "terms": {
                                              "field": "Fax",
                                              "size": 100000
                                            }
                                          },
                                            "poi_mds_filter": {
                                              "bucket_selector": {
                                                "buckets_path": {
                                                  "count_over_one": "grouped_Fax"
                                                },
                                                "script": "params.count_over_one > 1"
                                              }                                           
                                            }
                                        }
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
        }
    }
}

我的尝试结果仅使我回头数:“ doc_count”:26772 但是我需要的是完整数据列表(ID列除外),其中分组计数超过1。

0 个答案:

没有答案