2015-07-01 25 views
0

我有三組文檔(例如來自注冊,已驗證和未註冊用戶的文檔),並且我想使用衰減函數對它們進行評分。Elasticsearch衰變參數

但是,我需要對這三組文檔中的每一組都有不同的衰減速度(比例),以便來自驗證用戶的文檔比未註冊用戶的文檔長。

看來,不可能使用doc字段作爲衰減函數的參數。也許,還有其他方法可以實現我想要的?

回答

1

這可能與function_score來完成,函數定義的 「過濾器」:

{ 
    "size": 100, 
    "query": { 
    "function_score": { 
     "score_mode": "multiply", 
     "query": { 
     "bool": { 
      "must": [ 
      { 
       "term": { 
       "status": 0 
       } 
      }, 
      { 
       "term": { 
       "categories": 29 
       } 
      } 
      ] 
     } 
     }, 
     "functions": [ 
     { 
      "filter": { 
      "term": { 
       "user_type": 1 
      } 
      }, 
      "weight": 1, 
      "gauss": { 
      "date_created": { 
       "scale": "7d", 
       "decay": 0.9 
      } 
      } 
     }, 
     { 
      "filter": { 
      "not": { 
       "term": { 
       "user_type": 1 
       } 
      } 
      }, 
      "weight": 0.8, 
      "gauss": { 
      "date_created": { 
       "scale": "7d", 
       "decay": 0.8 
      } 
      } 
     } 
     ] 
    } 
    } 
}