前言
ES的查询经历 from + size、Scroll、SearchAfter等方式,都是为了逐一解决查询带来的性能问题,目前search after的查分方式最优
使用
GET twitter/_search
{
"size": 10,
"query": {
"match" : {
"title" : "elasticsearch"
}
},
"search_after": [1463538857, "654323"],
"sort": [
{"date": "asc"},
{"_id": "desc"}
]
}
在上述的查询中,发现是没有score得分的,但是如何才能返回score分数哪?
获取score
Tips: 按照 _score进行排序即可;
{
"query": {
"bool": {
"filter": [
{
"term": {
"docId": "2019_08_09_d0f4bfd720807a162bc228f1e8b65f7d"
}
}
],
"must_not": [],
"should": [
{
"match": {
"title": "elasticsearch"
}
}
]
}
},
"from": 0,
"size": 10,
"sort": [
{
"_score": "asc"
}
],
"aggs": {},
"search_after": [
0
]
}
返回结果:
"hits": {
"total": 1,
"max_score": null,
"hits": [
{
"_index": "mf_index_2019-08-09",
"_type": "docs",
"_id": "d0f4bfd720807a162bc228f1e8b65f7d",
"_score": 10.90702,
"_routing": "e37a0b0e72e44eb4b98a1ef58be206cd",
"_source": {
"country": "中国大陆",
"spamTag": "other",
"hyTaskType": "实时任务",
"pubTime": 1565348785000,