在我的文档中,我有一个字段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。有什么建议可能是错的吗?