我正在尝试使用嵌套对象中的值来提升基于custom_filters_score方法的排名。因此,不需要匹配,但如果匹配,则会提升排名。通常情况下,可以对boost进行硬编码,但我想根据嵌套文档中匹配的值使用script field。
如果我对一个值进行硬编码,比如1000,我可以看到对分数的影响。然而,就好像ES无法理解流行度键,因为它给它带来了无法提升。
文档看起来像是这样的,其中search_terms是type = nested,简单的两个键和两个值:
{
"name":"colorful light blue things that make developers wild"
"search_terms":[
{
"a_term":"colorful",
"popularity":33433
},
{
"a_term":"light blue",
"popularity":343
}
]
"other_keys":"stuff"
}
以下是custom_filters_score查询
的示例{
"query":{
"custom_filters_score":{
--query:{} would be here--
,"filters":[
{
"filter":{
"nested":{
"path":"search_terms"
,"query": {
"match": {
"a_term": "light blue"
}
}
}
},
--here is my problem area
"script":"doc['search_terms.popularity'].value"
-- this would work, hard coded value
"script":"1000"
}
]
}
}
答案 0 :(得分:0)
您应该在迭代它们时访问嵌套文档字段。在您的查询中,您尝试访问嵌套查询之外的嵌套字段。尝试这样的事情:
"query": {
"nested": {
"score_mode": "total",
"path": "search_terms",
"query": {
"function_score": {
"query": {
"match": {
"a_term": "light blue"
}
},
"script_score": {
"script": "doc['search_terms.popularity'].value"
},
"boost_mode": "replace"
}
}
}
}