通过使用term aggregation而非keyword aggregation实现通配符搜索:
GET /_search { "aggs": { "terms_agg": { "terms": { "field": "my_field.keyword", "include": "search_term.*" } } } }
使用multi-fields在聚合字段上定义多个mapping,例如:
PUT my_index { "mappings": { "properties": { "my_field": { "type": "text", "fields": { "keyword": { "type": "keyword" } } } } } }
然后使用"my_field.keyword"处理聚合请求。