创建一个索引
curl -s -XPUT 'http://localhost:9200/gino_test/' -d '{
"mappings": {
"tweet": {
"properties": {
"text": {
"type": "string",
"term_vector": "with_positions_offsets_payloads",
"store" : true,
"analyzer" : "fulltext_analyzer"
},
"fullname": {
"type": "string",
"term_vector": "with_positions_offsets_payloads",
"analyzer" : "fulltext_analyzer"
}
}
}
},
"settings" : {
"index" : {
"number_of_shards" : 1,
"number_of_replicas" : 0
},
"analysis": {
"analyzer": {
"fulltext_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"type_as_payload"
]
}
}
}
}
}'
插入测试数据:
| _index | _type | _id | text | fullname |
|---|---|---|---|---|
| gino_test | tweet | 1 | hello world | gino zhang |
| gino_test | tweet | 2 | gino like world cup | gino li |
| gino_test | tweet | 3 | my cup | jsper li |
简单情况:单字段匹配打分
POST http://192.168.102.216:9200/gino_test/_search
{
"explain": true,
"query": {
"match": {
"text": "my cup"
}
}
}
查询结果: score_example1.json https://drivenotepad.github.io/app/?state={%22action%22:%22open%22,%22ids%22:[%220B4dv03yigoV2VjFIbEI3ZFQwRlk%22]}
打分分析:
https://drive.google.com/open?id=1RZhu9j9NNy30KNYd4qwQ9b6o5utdnyq0yqzDhdW_5uo

https://drive.google.com/open?id=1B4fVZLiGvHAIrKH_zk7jTSVHjcXQC1Byd8tKXbNswck

本文深入探讨了ElasticSearch的打分机制,包括单字段匹配、multi-match的best_fields和cross_fields模式、should条件的权重、function_score的高级打分以及rescore的重打分策略,详细解析了各项打分因素和应用场景。
最低0.47元/天 解锁文章
1047





