Nat*_*lor 11 facet faceted-search elasticsearch
我已经将我的弹性搜索实现配置为通过映射中的id来对结果进行分析,当我向用户显示该方面时,我需要能够显示代表它的人类可读名称.我需要的数据都存在于映射中,但我不确定如何将其作为方面的一部分返回.当然有可能吗?
考虑下面的例子,我想小面给我一些方法来关联thingId到thingName(或其他任何thing可能需要的属性):
制图
{
thingId,
thingName
}
Run Code Online (Sandbox Code Playgroud)
分面查询
{
"facets":{
"things":{ "terms":{ "field":"thingId" } }
}
}
Run Code Online (Sandbox Code Playgroud)
结果
{
"hits":{
"total":3,
"max_score":1.0,
"hits":[
...
]
},
"facets":{
"things":{
"_type":"terms",
"missing":0,
"total":3,
"other":0,
"terms":[
{
"term":"5",
"count":1
},
{
"term":"4",
"count":1
},
{
"term":"2",
"count":1
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
编辑
关于Solr的这个答案建议我将两个属性(thingName和thingId)都面对,然后循环遍历两个方面结果集,假设项目的顺序是相同的.我不知道会有多可靠,但这是一个选择.
编辑2
这个答案表明,如果不将两个领域合并为一个单一的价值并且面对这个问题,就不可能做我想做的事情:thingId|thingName.不理想.
编辑3
这个答案建议将这些值组合成一个字段并在其上进行分面(如上所述),但它使用术语脚本来实现组合,因此不需要我索引值的组合形式.仍然不完美,但似乎是最糟糕的选择.
如果您不喜欢使用术语脚本,那么另一个选择是使用嵌套聚合,假设您能够使用 1.0.0。
您的聚合将如下所示:
{
"query": {
"match_all": {}
},
"aggs": {
"theIds": {
"terms" : {
"field": "thingId"
},
"aggs":{
"theNames": {
"terms": {
"field": "thingName"
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
响应会是这样的:
"aggregations": {
"theIds": {
"buckets": [
{
"key": "1",
"doc_count": 5,
"theNames": {
"buckets": [
{
"key": "AAA",
"doc_count": 3
},
{
"key": "BBB",
"doc_count": 3
},
{
"key": "CCC",
"doc_count": 2
}
]
}
},
{
"key": "2",
"doc_count": 2,
"theNames": {
"buckets": [
{
"key": "AAA",
"doc_count": 2
}
]
}
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1444 次 |
| 最近记录: |