POST news_index/_bulk {"index":{"_id":1}} {"title":"ElasticSearch原理- 神一样的存在"} {"index":{"_id":2}} {"title":"Elasticsearch 快速开始","like":5} {"index":{"_id":3}} {"title":"开源搜索与分析· Elasticsearch","like":10} {"index":{"_id":4}} {"title":"铭毅天下 死磕Elasticsearch", "like":1000} GET news_index/_search { "query": { "function_score": { "query": { "match": { "title": "Elasticsearch" } }, "field_value_factor": { "field": "like", "modifier": "log1p", "factor": 0.1, "missing": 1 }, "boost_mode": "sum" } } }
评分计算公式解读:new_score = old_score + log(1 + 0.1 * like值)- missing含义:使用 field_value_factor 时要注意,有的文档可能会缺少这个字段,加上 missing 来个这些缺失字段的文档一个缺省值