elasticsearch - 大写字母在弹性搜索中应该排在第一位
问题描述
我有一些数据,比如......芒果、苹果、香蕉、胡萝卜
我正在寻找弹性搜索排序查询,它应该给出结果,因为大写字母应该首先出现,如下所示
香蕉、芒果、苹果、胡萝卜
任何人都可以帮助我如何准备针对此要求的查询。谢谢
解决方案
使用该keyword
字段并按顺序对数据进行asc
排序,您将能够获得所需的结果。
添加具有索引数据、映射、搜索查询和搜索结果的工作示例
索引映射:
{
"mappings": {
"properties": {
"name": {
"type": "keyword"
}
}
}
}
指数数据:
{
"name": "apple"
}
{
"name": "Banana"
}
{
"name": "Mango"
}
{
"name": "carrot"
}
搜索查询:
{
"sort": [
{
"name": {
"order": "asc"
}
}
]
}
搜索结果:
"hits": [
{
"_index": "65624606",
"_type": "_doc",
"_id": "3",
"_score": null,
"_source": {
"name": "Banana"
},
"sort": [
"Banana"
]
},
{
"_index": "65624606",
"_type": "_doc",
"_id": "1",
"_score": null,
"_source": {
"name": "Mango"
},
"sort": [
"Mango"
]
},
{
"_index": "65624606",
"_type": "_doc",
"_id": "2",
"_score": null,
"_source": {
"name": "apple"
},
"sort": [
"apple"
]
},
{
"_index": "65624606",
"_type": "_doc",
"_id": "4",
"_score": null,
"_source": {
"name": "carrot"
},
"sort": [
"carrot"
]
}
]
推荐阅读
- azure - 有什么办法可以防止在交换插槽时交换云配置?
- python - 按降序对numpy多维数组的每一行进行排序
- visual-studio - 在 vs 代码中用松露编译 OpenZeppelin 导入的合约时出错
- python - 如何使用图像加载训练有素的模型作业库?
- c# - 错误 MSB4236:找不到指定的 SDK 'Microsoft.NET.Sdk.web' - .NET 5.0
- reactjs - 使用 useHistory 钩子重定向到具有不同查询参数的特定 url
- awk - 删除根据模式解释的重复项失败
- html - 选项卡内容显示一个在另一个之下
- django - Django 一个简单的查询让我抓狂 ''int' object is not iterable'
- crm - 解决 ZohoCRM-SDK 中的无效代码错误