1,插入测试数据
PUT testscore/_bulk
{"index":{"_id":1}}
{"name":"i like elastic search", "content":"elastic search is a great tool"}
{"index":{"_id":2}}
{"name":"elastic search", "content":"elastic search is a great tool, i will not give up studying it"}
2,相关性demo
文档2和文档1的tf都是1,但是文档2更短,所以排在了前面
GET testscore/_search
{
"explain": true,
"query": {
"match": {
"content": "elastic search"
}
}
}
3,boosting控制相关性
GET testscore/_search
{
"query": {
"boosting": {
"negative": {
"term": {
"content": {
"value": "elastic"
}
}
},
"positive": {
"term": {
"content": {
"value": "tool"
}
}
},
"negative_boost": 0.2
}
}
}