2016-11-14 54 views
0

我有我已經簡化到這樣的查詢:Elasticsearch功能評分查詢得分

GET /foos-33/_search 
{ 
    "from" : 0, 
    "size" : 25, 
    "query" : { 
    "function_score" : { 
     "query" : { 
     "bool" : { 
      "filter" : { 
      "bool" : { 
       "must" : [ { 
       "bool" : { 
        "must_not" : { 
        "terms" : { 
         "foo.id" : [ ] 
        } 
        } 
       } 
       } ] 
      } 
      } 
     } 
     }, 
     "functions" : [ { 
     "field_value_factor" : { 
      "field" : "foo.strategicBoost", 
      "missing" : 1.0 
     } 
     } ], 
     "score_mode" : "sum" 
    } 
    }, 
    "explain" : true, 
    "sort" : [ { 
    "counts.barsPerDay" : { 
     "order" : "desc" 
    } 
    } ] 
} 

命中的得分始終爲零。解釋輸出排序顯示爲什麼發生這種情況,但我不完全理解這是怎麼回事:

 "_explanation": { 
      "value": 0, 
      "description": "function score, product of:", 
      "details": [ 
       { 
       "value": 0, 
       "description": "ConstantScore(-() +*:*), product of:", 
       "details": [ 
        { 
         "value": 0, 
         "description": "boost", 
         "details": [] 
        }, 
        { 
         "value": 1, 
         "description": "queryNorm", 
         "details": [] 
        } 
       ] 
       }, 
       { 
       "value": 10, 
       "description": "min of:", 
       "details": [ 
        { 
         "value": 10, 
         "description": "field value function: none(doc['foo.strategicBoost'].value?:1.0 * factor=1.0)", 
         "details": [] 
        }, 
        { 
         "value": 3.4028235e+38, 
         "description": "maxBoost", 
         "details": [] 
        } 
       ] 
       } 
      ] 
     } 
    }, 

我試圖把它包在constant_score從0常數比分改爲1,這樣的:

GET /foos-33/_search 
{ 
    "from" : 0, 
    "size" : 25, 
    "query" : { 
    "function_score" : { 
     "query" : { 
     "bool" : { 
      "constant_score": { 
       "boost": 1, 
      "filter" : { 
      "bool" : { 
       "must" : [ { 
       "bool" : { 
        "must_not" : { 
        "terms" : { 
         "foo.id" : [ ] 
        } 
        } 
       } 
       } ] 
      } 
      } 
      } 
     } 
     }, 
     "functions" : [ { 
     "field_value_factor" : { 
      "field" : "foo.strategicBoost", 
      "missing" : 1.0 
     } 
     } ], 
     "score_mode" : "sum" 
    } 
    }, 
    "explain" : true, 
    "sort" : [ { 
    "counts.barsPerDay" : { 
     "order" : "desc" 
    } 
    } ] 
} 

但是這給了我一個錯誤信息:

"failed_shards": [ 
    { 
     "shard": 0, 
     "index": "foos-33", 
     "node": "A9s2Ui3mQE2SBZhY2VkZGw", 
     "reason": { 
      "type": "query_parsing_exception", 
      "reason": "[bool] query does not support [constant_score]", 
      "index": "foos-33", 
      "line": 8, 
      "col": 29 
     } 
    } 
    ] 

還有另一種方法我可以嘗試解決這個問題 - 我可以嘗試到product更改爲sum或東西 - 但我無法揣摩出product的來源。

回答

0

頂層「的產物」來自boost_mode,默認爲multiply。設置boost_modereplace在這種情況下,正確的修復 - 查詢成績永遠是零,所以我們不關心它。設置boost_modesum會在這種情況下一個同樣有效修復了。