我正在使用 ElasticSearch,我想知道是否可以使用 faceting 来检索我的结果中的一些统计信息,更具体地说,是我的结果中提到最多的人。我已经有一个包含该信息的字段。但是现在,当我想按多个单词对它进行分组时,我的构面结果会按术语破坏该字段中的数据。
即:如果用户搜索 John,我想获取诸如
{
[...]
"facets" : {
"topPeople" : {
"_type" : "terms",
"missing" : 0,
"total" : 1739884,
"other" : 1705319,
"terms" : [ {
"term" : "John Smith",
"count" : 13954
}, {
"term" : "John Snow",
"count" : 1432
}, {
"term" : "John Baird",
"count" : 770
}]
}
}
相反,ElasticSearch 按术语分解结果并返回如下内容:
{
[...]
"facets" : {
"topPeople" : {
"_type" : "terms",
"missing" : 0,
"total" : 1739884,
"other" : 1705319,
"terms" : [ {
"term" : "John",
"count" : 1739884
}, {
"term" : "Smith",
"count" : 13954
}, {
"term" : "Snow",
"count" : 1432
}]
}
}
I read somewhere that if I set the index to not be analyzed, ElasticSearch should return the complete string of words. However, I still want the user to be able to search on the field. I would like to avoid duplicating the field to have a non-analyzed one. Is there any way to get grouping per field with ElasticSearch?
I am currently using the following facet query:
{
"query" : {
[...]
},
"facets" : {
"topPeople" : {
"terms" : {
"field" : "people",
"size" : 3
}
}
}
}