【发布时间】:2016-10-30 02:54:26
【问题描述】:
我的索引上有一个not analyzed 字段:
"city": { "type": "string", "index": "not_analyzed" }
我有如下聚合:
"aggs": {
"city": {
"terms": {
"field": "city"
}
}
}
这给了我这样的输出:
"aggregations": {
"city": {
"doc_count_error_upper_bound": 51,
"sum_other_doc_count": 12478,
"buckets": [
{
"key": "New York",
"doc_count": 28420
},
{
"key": "London",
"doc_count": 23456
},
{
"key": "São Paulo",
"doc_count": 12727
}
]
}
}
我需要在处理聚合之前添加一个match_phrase_prefix 查询,以根据用户文本过滤我的结果,如下所示:
{
"size": 0,
"query": {
"match_phrase_prefix": {
"city": "sao"
}
},
"aggs": {
"city": {
"terms": {
"field": "city"
}
}
}
}
结果是……什么都没有!
"aggregations": {
"city": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": []
}
}
我期待São Paulo city 的聚合结果。显然问题是我的字段应该有 lowercase 和 asciifolding 过滤器才能匹配(São/sao),但我无法分析我的字段,因为我不想有像 São 这样的聚合结果、Paulo、New、York(在分析字段上会发生这种情况)。
我能做什么?我尝试了很多与映射/查询/聚合的组合,但我无法让它工作。
任何帮助将不胜感激。
【问题讨论】:
标签: elasticsearch