阅读本文需要先了解function_score的相关知识,请看 ElasticSearch - function_score 简介
首先准备数据和索引,在ES插入三笔数据,其中title是text类型,like是integer类型(代表点赞量)
{ "title": "ES 入门", "like": 2 } { "title": "ES 进阶", "like": 5 } { "title": "ES 最高难度", "like": 10 }
先使用一般的query,查看普通的查询的评分会是如何
GET 127.0.0.1/mytest/doc/_search { "query": { "match": { "title": "ES" } } }
"hits": [ { "_score": 0.2876821, "_source": { "title": "ES 入门", "like": 2 } }, { "_score": 0.20309238, "_source": { "title": "ES 进阶", "like": 5 } }, { "_score": 0.16540512, "_source": { "title":