在我的文档中,我有一个字段collaboration,我想在这个字段上进行聚合查询。然而,我也希望它是全文可搜索的,所以我想我应该让它成为一个多字段。该字段可能如下所示:
...
"collaboration" : "CMS"
or
"collaboration" : ["ATLAS", "CMS"]
or
"collaboration" : "LHCb"
...按照此建议:ElasticSearch term aggregation我将映射更改为:
"collaboration": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},我运行了一个查询:
POST /my_index/_search
{
"aggs": {
"collaboration": {
"terms": {
"field": "collaboration.raw"
}
}
}
}却一无所获:
"hits": {
"total": 5,
"max_score": 1,
"hits": [...]
},
"aggregations": {
"collaboration": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": []
}
}即使我尝试使用这个字段进行搜索,它也不起作用:
POST /my_index/_search
{
"query": {
"query_string": {
"query": "CMS",
"fields": ["collaboration.raw"]
}
}
}我是否应该更改映射,因为字段有时是一个列表,有时是一个字符串?我的研究发现arrays are supposed to be supported out of the box。有什么建议吗?这里可能有什么问题?
发布于 2015-07-08 12:35:57
多亏Andrei Stefan解决了这个问题!
所有文件都需要在更改地图后重新编制索引,这些细节虽小但令人痛苦。
https://stackoverflow.com/questions/31292283
复制相似问题