我在 Elastic Search 中为包含数组的文档编制索引。
样本文件:
doc1:
{
...
actors: ["Tom Cruise", "Brad Pitt", ...],
...
}
doc2:
{
...
actors: ["Brad Pitt", "Tom Cruise", ...],
...
}
在此类文档中搜索时,我希望得分取决于数组中的匹配位置,这意味着在示例文档中,搜索“Tom Cruise”应该提升第一个文档doc1
,因为它的匹配位置是1
.
我现在能想到的唯一解决方案是添加有限数量的包含第一个演员的字段(大约 5 个),并进行提升,例如:
doc1:
{
...
actors: ["Tom Cruise", "Brad Pitt", ...],
actor1: "Tom Cruise",
actor2: "Brad Pitt",
...
}
随着,等actor1
的提升。5
actor2
4
你有更好的解决方案来处理这个问题,也许使用custom_score
?
谢谢 !