您可以通过结合
boosting查询和
custom_score查询来实现
与其提高年份,不如根据年份更改分数,因为:
(_score + 2013) > (_score + 1999)
较新的结果将浮动到顶部。
通过使用增强查询,我们可以有效地将缺少奖励字段的结果降级。
请参阅:http : //www.elasticsearch.org/guide/reference/query-dsl/boosting-
query.html http://www.elasticsearch.org/guide/reference/query-dsl/custom-
score-query.html
_client.Search<Entry>(s=>s .Query(q =>q .Boosting(bq=>bq .Positive(pq=>pq .CustomScore(cbf=>cbf .Query(cbfq=>cbfq .QueryString(qs => qs .onFieldsWithBoost(d => d.Add(entry => entry.Title, 5.0) .Add(entry => entry.Description, 2.0) ) .Query(searchText) ) ) .script("_score + doc['year'].value") ) ) .Negative(nq=>nq .Filtered(nfq=>nfq .Query(qq=>qq.MatchAll()) .Filter(f=>f.Missing(p=>p.Award)) ) ) .NegativeBoost(0.2) ) ));


