Можно как-то так, но это будет есть достаточно много памяти, если таких комбинаций параметров слишком много. Так что лучше будет создать отдельное поле, в котором все эти поля будут уже слиты, тогда можно будет убрать script и просто использовать это поле.
DELETE test
PUT test
POST test/_bulk
{"index":{}}
{"destination":{"domain":"site.com"},"source":{"geo":{"continent_name":"Europe","region_iso_code":"RU-SPE","city_name":"St Petersburg","country_iso_code":"RU","region_name":"St.-Petersburg","location":{"lon":30.2642,"lat":59.8944}},"as":{"number":15378,"organization":{"name":"T2 Mobile LLC"}},"ip":"176.59.18.80"},"user_agent":{"original":"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36","os":{"name":"Windows 7"},"name":"Chrome","device":{"name":"Other"},"version":"41.0.2228"}}
{"index":{}}
{"destination":{"domain":"site.net"},"source":{"geo":{"continent_name":"Europe","country_iso_code":"RU","location":{"lon":37.6068,"lat":55.7386}},"as":{"number":31224,"organization":{"name":"PJSC MegaFon"}},"ip":"31.173.103.230"},"user_agent":{"original":"Mozilla/5.0 (Linux; arm_64; Android 7.1.1; ZC553KL) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 YaBrowser/20.2.0.215.00 Mobile Safari/537.36","os":{"name":"Android","version":"7.1.1","full":"Android 7.1.1"},"name":"Yandex Browser","device":{"name":"Generic Smartphone"},"version":"20.2.0"}}
{"index":{}}
{"destination":{"domain":"site.ru"},"source":{"geo":{"continent_name":"Europe","region_iso_code":"CZ-10","city_name":"Prague","country_iso_code":"CZ","region_name":"Hlavni mesto Praha","location":{"lon":14.4667,"lat":50.0833}},"as":{"number":13335,"organization":{"name":"Cloudflare, Inc."}},"ip":"141.101.95.78"},"user_agent":{"original":"Mozilla/5.0 (compatible;Cloudflare-Healthchecks/1.0;+https://www.cloudflare.com/; healthcheck-id: 78a4266622fe6057)","name":"Other","device":{"name":"Other"}}}
{"index":{}}
{"destination":{"domain":"site.com"},"source":{"geo":{"continent_name":"North America","region_iso_code":"US-VA","city_name":"Ashburn","country_iso_code":"US","region_name":"Virginia","location":{"lon":-77.539,"lat":39.018}},"as":{"number":39572,"organization":{"name":"DataWeb Global Group B.V."}},"ip":"46.229.168.163"},"user_agent":{"original":"Mozilla/5.0 (compatible; SemrushBot/6~bl; +http://www.semrush.com/bot.html)","name":"SemrushBot","device":{"name":"Spider"},"version":"6"}}
{"index":{}}
{"destination":{"domain":"site.info"},"source":{"geo":{"continent_name":"North America","region_iso_code":"US-VA","city_name":"Ashburn","country_iso_code":"US","region_name":"Virginia","location":{"lon":-77.539,"lat":39.018}},"as":{"number":39572,"organization":{"name":"DataWeb Global Group B.V."}},"ip":"46.229.168.102"},"user_agent":{"original":"Mozilla/5.0 (compatible; SemrushBot/6~bl; +http://www.semrush.com/bot.html)","name":"SemrushBot","device":{"name":"Spider"},"version":"6"}}
POST test/_search
{
"size": 0,
"aggs": {
"client": {
"terms": {
"script": {
"source": "(doc['source.geo.region_name.keyword'].size() > 0 ? doc['source.geo.region_name.keyword'].value : 'N/A') + '|' + (doc['source.as.organization.name.keyword'].size() > 0 ? doc['source.as.organization.name.keyword'].value : 'N/A') + '|' + (doc['user_agent.original.keyword'].size() > 0 ? doc['user_agent.original.keyword'].value : 'N/A')",
"lang": "painless"
},
"min_doc_count": 2
},
"aggs": {
"results": {
"top_hits": {
"size": 10
}
},
"domain_count": {
"cardinality": {
"field": "destination.domain.keyword"
}
},
"sales_bucket_filter": {
"bucket_selector": {
"buckets_path": {
"domainCount": "domain_count"
},
"script": "params.domainCount > 1"
}
}
}
}
}
}