如何在弹性搜索中按字母顺序对名称字段进行排序



我对名称字段有以下定义:

"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},

我该如何按字母顺序排序?

我正在尝试以下

{
"query": {
"match": {
"name": "Shoes"
}
},
"sort": {
"keyword": {
"order": "asc"
}  
},
"size": 10,
"from": 0,
"sort": []
}

但不知怎么的,这类人似乎什么都没做。

我已经提到了这些线程,但它们似乎对我的没有帮助

线程1

线程2

您需要参考name.keyword子字段,并且您的搜索中有两个不同的sort部分,请删除空的部分:

{
"query": {
"match": {
"name": "Shoes"
}
},
"sort": {
"name.keyword": {         <---- change this
"order": "asc"
}  
},
"size": 10,
"from": 0,
"sort": []                  <---- remove this
}

最新更新