我收集了一系列名字。
team dhoni
dhoni1
dibeesh 200
bb vineesh
devan
我想按字母升序(A - Z)对它进行排序,如下面的顺序
bb vineesh
devan
dhoni1
dibeesh 200
team dhoni
映射
"first_name": {
"type": "string",
"store": "true"
},
我试过了
{
"sort": [
{
"first_name": {
"order": "asc"
}
}
],
"query": {
"match_all": {
}
}
}
当我运行此查询时,我按以下顺序获取名称。
dibeesh 200
bb vineesh
devan
team dhoni
dhoni1
Elastic 搜索以带数字的名字作为首选。
我怎样才能避免这种情况?
最佳答案
我有一个类似的问题,另一个答案对我来说不太明白。我提到了 this documentation相反,并且能够通过这样的映射来解决
"name": {
"type": "string",
"analyzer": "english",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
}
然后这样查询排序
{
"query": {
"match": {
"name": "dhoni"
}
},
"sort": {
"name.raw": {
"order": "asc"
}
}
}
关于elasticsearch - 基于第一个字符的 Elasticsearch 字母排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25195653/