Sie benötigen eine pattern_capture
filter, die nur erfassen sollte, was nach @
ist. Auch nicht zu Chaos mit der ursprünglichen Analyse des Textes, schlage ich vor, ein Unterfeld zum Original email
Feld hinzufügen und damit arbeiten nur für diese spezifische Aggregation:
PUT /test
{
"settings": {
"analysis": {
"filter": {
"email_domains": {
"type": "pattern_capture",
"preserve_original" : 0,
"patterns": [
"@(.+)"
]
}
},
"analyzer": {
"email": {
"tokenizer": "uax_url_email",
"filter": [
"email_domains",
"lowercase",
"unique"
]
}
}
}
},
"mappings": {
"emails": {
"properties": {
"email": {
"type": "string",
"fields": {
"domain": {
"type": "string",
"analyzer": "email"
}
}
}
}
}
}
}
Der Versuch, für einige Testdaten:
POST /test/emails/_bulk
{"index":{"_id":"1"}}
{"email": "[email protected]"}
{"index":{"_id":"2"}}
{"email": "[email protected], [email protected]"}
{"index":{"_id":"3"}}
{"email": "[email protected]"}
{"index":{"_id":"4"}}
{"email": "[email protected]"}
{"index":{"_id":"5"}}
{"email": "[email protected]"}
Und für Ihren speziellen Anwendungsfall, eine einfache Aggregation wie folgt aus sollte es tun:
GET /test/emails/_search
{
"size": 0,
"aggs": {
"by_domain": {
"terms": {
"field": "email.domain",
"size": 10
}
}
}
}
Und das Ergebnis ist wie folgt aus:
"aggregations": {
"by_domain": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "outlook.com",
"doc_count": 3
},
{
"key": "gmail.com",
"doc_count": 2
},
{
"key": "yahoo.com",
"doc_count": 1
}
]
}
}