首页 > 解决方案 > 在 elasticsearch 上排序未按预期工作

问题描述

我有如下的 ES 查询:

{"query":{"bool":{"must":[{"bool":{"should":[{"bool":{"must":[{"bool":{"should":[{"match":{"*login*":{"query":"jyo","operator":"and"}}}]}}],"boost":1.34}}]}}]}},"sort":[{"_uid":"desc"}]}
The output is :

{
    "took": 77,
    "timed_out": false,
    "_shards": {
        "total": 33,
        "successful": 33,
        "failed": 0
    },
    "hits": {
        "total": 4,
        "max_score": null,
        "hits": [
            {
                "_index": "hobbes1.qa_en_19_2",
                "_type": "esuser",
                "_id": "6",
                "_score": null,
                "sort": [
                    "esuser#6"
                ]
            },
            {
                "_index": "hobbes1.qa_en_19_2",
                "_type": "esuser",
                "_id": "5",
                "_score": null,
                "sort": [
                    "esuser#5"
                ]
            },
            {
                "_index": "hobbes1.qa_en_19_2",
                "_type": "esuser",
                "_id": "4",
                "_score": null,
                "sort": [
                    "esuser#4"
                ]
            },
            {
                "_index": "hobbes1.qa_en_19_2",
                "_type": "esuser",
                "_id": "10003",
                "_score": null,
                "sort": [
                    "esuser#10003"
                ]
            }
        ]
    }
}

如果按_id排序,那么10003不应该排在最前面吗?我正在使用弹性搜索 1.7 版。请帮忙。

标签: elasticsearch

解决方案


因为_idis not a numberbut a string,所以“10003”在字符串比较时小于“4”、“5”或“6”。


推荐阅读