我目前有类似的东西:
"aggs": { "group_by_myfield": { "terms": { "field": "myfield" } } }
但是,myfield的值为“ alpha 1.0”,“ alpha 2.0”,“ beta 1.0”。现在,我只想聚合值“ alpha”,“ beta”。我怎么做?我试过了:
"aggs": { "group_by_myfield": { "terms": { "field": "myfield" "script": "_value.split()[0]" } } }
但我想这里没有拆分功能。欢迎任何建议!
我设法通过粘贴在问题中的链接来完成此任务:
GET _search { "size": 0, "aggs": { "group_by_myfield": { "terms": { "field": "myfield", "script": "_value.replaceAll('\\\\s+.*','')" } } } }