1

我正在尝试使用嵌套对象中的值来根据custom_filters_score方法提高我的排名。因此,不需要匹配,但如果匹配,它将提高排名。通常,可以硬编码提升,但我想使用基于嵌套文档中匹配的值的脚本字段。

如果我硬编码一个值,比如 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"           
             }
         ]
     }    
 }
4

1 回答 1

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"
          }
      }
   }
}
于 2014-01-17T14:00:55.273 回答