问题
when i do terms aggregation on string field (with whitespace tokenizer) i have results for each word (token), but i need results for whole strings. How can i do aggregation on string field like terms but group output by whole string, not by tokens?
I already saw this solutions: ElasticSearch term aggregation Terms aggregation based on unique key but they are based on keyword tokenizer
I can't use keyword tokenizer, because of i wan't apply stopwords filter while indexing
回答1:
I just had the same problem, and came here looking for a solution.
And then it dawned on me. there's a .raw (unanalyzed) field, and it worked. The solution was to use it.
So the aggregation went from:
{
"aggs": {
"keys": {
"terms": {
"size": 0,
"field": "key"
}}}}}
to:
{
"aggs": {
"keys": {
"terms": {
"size": 0,
"field": "key.raw"
}}}}}
来源:https://stackoverflow.com/questions/27815875/elasticsearch-terms-aggregation-on-tokenized-field