弹性6.3排序未按预期工作

时间:2018-08-17 12:37:06

标签: elasticsearch

以下查询应返回所有用户区域为德国的文档,并应在用户ID字段上进行排序。但是,排序无法正常进行。它应该以用户ID 2开头,但是以10和2开头在中间。

用户区域的映射类型是关键字,用户ID是关键字(用户ID可以是一个字符串,为简便起见,此处仅使用整数)。

任何人都可以指出查询出了什么问题。

查询:

{
    "size" : 10,
    "query": {
        "constant_score" : {
            "filter" : {
                "term" : { "user-region" : "germany"}
            }
        }
    },
  "sort": [
    {
      "user-id": {
        "order": "asc"
      }
    }
  ]
}


{
    "took": 1,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 20,
        "max_score": null,
        "hits": [
            {
                "_index": "user",
                "_type": "_doc",
                "_id": "10",
                "_score": null,
                "_source": {
                    "is-admin": false,
                    "docType": ":cm:user",
                    "user-id": "10",
                    "user-region": "germany",

                    "version": "1.0"
                },
                "sort": [
                    "10"
                ]
            },
            {
                "_index": "user",
                "_type": "_doc",
                "_id": "12",
                "_score": null,
                "_source": {
                    "is-admin": false,
                    "docType": ":cm:user",
                    "user-id": "12",
                    "oem-id": "germany",

                    "version": "1.0"
                },
                "sort": [
                    "12"
                ]
            },
            {
                "_index": "user",
                "_type": "_doc",
                "_id": "14",
                "_score": null,
                "_source": {
                    "is-admin": false,
                    "docType": ":cm:user",
                    "user-id": "14",
                    "oem-id": "germany",

                    "version": "1.0"
                },
                "sort": [
                    "14"
                ]
            },
            {
                "_index": "user",
                "_type": "_doc",
                "_id": "16",
                "_score": null,
                "_source": {
                    "is-admin": false,
                    "docType": ":cm:user",
                    "user-id": "16",
                    "oem-id": "germany",

                    "version": "1.0"
                },
                "sort": [
                    "16"
                ]
            },
            {
                "_index": "user",
                "_type": "_doc",
                "_id": "18",
                "_score": null,
                "_source": {
                    "is-admin": false,
                    "docType": ":cm:user",
                    "user-id": "18",
                    "oem-id": "germany",

                    "version": "1.0"
                },
                "sort": [
                    "18"
                ]
            },
            {
                "_index": "user",
                "_type": "_doc",
                "_id": "2",
                "_score": null,
                "_source": {
                    "is-admin": false,
                    "docType": ":cm:user",
                    "user-id": "2",
                    "oem-id": "germany",

                    "version": "1.0"
                },
                "sort": [
                    "2"
                ]
            },
            {
                "_index": "user",
                "_type": "_doc",
                "_id": "20",
                "_score": null,
                "_source": {
                    "is-admin": false,
                    "docType": ":cm:user",
                    "user-id": "20",
                    "oem-id": "germany",

                    "version": "1.0"
                },
                "sort": [
                    "20"
                ]
            },
            {
                "_index": "user",
                "_type": "_doc",
                "_id": "22",
                "_score": null,
                "_source": {
                    "is-admin": false,
                    "docType": ":cm:user",
                    "user-id": "22",
                    "oem-id": "germany",

                    "version": "1.0"
                },
                "sort": [
                    "22"
                ]
            },
            {
                "_index": "user",
                "_type": "_doc",
                "_id": "24",
                "_score": null,
                "_source": {
                    "is-admin": false,
                    "docType": ":cm:user",
                    "user-id": "24",
                    "oem-id": "germany",

                    "version": "1.0"
                },
                "sort": [
                    "24"
                ]
            },
            {
                "_index": "user",
                "_type": "_doc",
                "_id": "26",
                "_score": null,
                "_source": {
                    "is-admin": false,
                    "docType": ":cm:user",
                    "user-id": "26",
                    "oem-id": "germany",

                    "version": "1.0"
                },
                "sort": [
                    "26"
                ]
            }
        ]
    }
}

0 个答案:

没有答案