Elasticsearch中的意外(不区分大小写)字符串排序

ale*_*bie 4 sorting case-insensitive elasticsearch

我有一个我正在Elasticsearch中排序的控制台平台列表.

以下是"名称"字段的映射:

{
    "name": {
        "type": "multi_field",
        "fields": {
            "name": {
                "type": "string",
                "index": "analyzed"
            },
            "sort_name": {
                "type": "string",
                "index": "not_analyzed"
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

当我执行以下查询时

{
  "query": {
    "match_all": {}
  },
    "sort": [
        {
          "name.sort_name": { "order": "asc" }
        }
    ],
    "fields": ["name"]
}
Run Code Online (Sandbox Code Playgroud)

我得到这些结果:

{
    "took": 1,
    "timed_out": false,
    "_shards": {
        "total": 3,
        "successful": 3,
        "failed": 0
    },
    "hits": {
        "total": 17,
        "max_score": null,
        "hits": [
            {
                "_index": "platforms",
                "_type": "platform",
                "_id": "1393602489",
                "_score": null,
                "fields": {
                    "name": "GameCube"
                },
                "sort": [
                    "GameCube"
                ]
            },
            {
                "_index": "platforms",
                "_type": "platform",
                "_id": "1393602490",
                "_score": null,
                "fields": {
                    "name": "Gameboy Advance"
                },
                "sort": [
                    "Gameboy Advance"
                ]
            },


    {
            "_index": "platforms",
            "_type": "platform",
            "_id": "1393602498",
            "_score": null,
            "fields": {
                "name": "Nintendo 3DS"
            },
            "sort": [
                "Nintendo 3DS"
            ]
        },

        ...remove for brevity ...

        {
            "_index": "platforms",
            "_type": "platform",
            "_id": "1393602493",
            "_score": null,
            "fields": {
                "name": "Xbox 360"
            },
            "sort": [
                "Xbox 360"
            ]
        },
        {
            "_index": "platforms",
            "_type": "platform",
            "_id": "1393602502",
            "_score": null,
            "fields": {
                "name": "Xbox One"
            },
            "sort": [
                "Xbox One"
            ]
        },
        {
            "_index": "platforms",
            "_type": "platform",
            "_id": "1393602497",
            "_score": null,
            "fields": {
                "name": "iPhone/iPod"
            },
            "sort": [
                "iPhone/iPod"
            ]
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

一切都按预期排序,除了iPhone/iPod结果在最后(而不是在GameBoy Advance之后) - 为什么/名称对排序有影响?

谢谢

ale*_*bie 15

好的,所以我发现原因与此无关/.ES将按大写字母和小写字母排序.

settings在索引创建中添加了一个自定义分析器:

{
    "analysis": {
        "analyzer": {
            "sortable": {
                "tokenizer": "keyword",
                "filter": [
                    "lowercase"
                ]
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

然后在字段映射中我添加'analyzer': 'sortable'sort_name多字段.