首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >弹性搜索排序

弹性搜索排序
EN

Stack Overflow用户
提问于 2018-08-20 12:25:49
回答 1查看 54关注 0票数 0

我的数据排序后是这样的:以下是排序后的响应。但这并不是预期的输出。

代码语言:javascript
复制
{
    "took": 1,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
    },
    "hits": {
        "total": 8,
        "max_score": null,
        "hits": [
            {
                "_index": "test",
                "_type": "size",
                "_id": "AWVVTy-v9pbhY5QtJPGe",
                "_score": null,
                "_source": {
                    "e_size": "5"
                },
                "sort": [
                    "5"
                ]
            },
            {
                "_index": "test",
                "_type": "size",
                "_id": "AWVVTmY89pbhY5QtJPGa",
                "_score": null,
                "_source": {
                    "e_size": "3"
                },
                "sort": [
                    "3"
                ]
            },
            {
                "_index": "test",
                "_type": "size",
                "_id": "AWVVTxXe9pbhY5QtJPGd",
                "_score": null,
                "_source": {
                    "e_size": "100"
                },
                "sort": [
                    "100"
                ]
            },
            {
                "_index": "test",
                "_type": "size",
                "_id": "AWVVTpYJ9pbhY5QtJPGc",
                "_score": null,
                "_source": {
                    "e_size": "10-"
                },
                "sort": [
                    "10-"
                ]
            },
            {
                "_index": "test",
                "_type": "size",
                "_id": "AWVVTk1x9pbhY5QtJPGY",
                "_score": null,
                "_source": {
                    "e_size": "1-7"
                },
                "sort": [
                    "1-7"
                ]
            },
            {
                "_index": "test",
                "_type": "size",
                "_id": "AWVVTnsm9pbhY5QtJPGb",
                "_score": null,
                "_source": {
                    "e_size": "1-6"
                },
                "sort": [
                    "1-6"
                ]
            },
            {
                "_index": "test",
                "_type": "size",
                "_id": "AWVVTjAq9pbhY5QtJPGX",
                "_score": null,
                "_source": {
                    "e_size": "1-2"
                },
                "sort": [
                    "1-2"
                ]
            },
            {
                "_index": "test",
                "_type": "size",
                "_id": "AWVVThkT9pbhY5QtJPGW",
                "_score": null,
                "_source": {
                    "e_size": "1"
                },
                "sort": [
                    "1"
                ]
            }
        ]
    }
}

下面是用于获得结果的排序。

代码语言:javascript
复制
 {
     "sort": [{
         "e_size": {
             "order": "desc"

         }
     }]
 }

e_size类型为"String“,索引为"not_analyzed”

如何解决这个排序问题。我们需要使用任何分析器来做这个吗。或者e_size数据类型应该不同。

EN

回答 1

Stack Overflow用户

发布于 2018-08-20 13:03:50

它已经正确地对它进行了排序。您可以尝试自己对这些字符串进行排序,也会得到相同的结果。

示例:["100", "10-"]

这里是"0" < "-",这就是为什么"10-""100"之后,以此类推。你可以把它看作是如何在字典中找到一些单词。

e_size设置为数字或对每个e_size使用任何不同的字符串系列

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51924152

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档