elasticsearch - 弹性搜索排序 - 非嵌套元素
问题描述
我想在弹性搜索中使用排序。我尝试了 ES 中建议的嵌套排序 - 嵌套排序示例
但后来我发现我的索引挡住了,属性不是“嵌套”类型。
那么对非嵌套类型的内部元素进行排序的最佳方法是什么。
我希望在 MDMGlobalData.City 字段中使用排序
解决方案
好的,我试图复制你的问题
PUT my_index
{
"mappings": {
"properties": {
"MDMGlobalData": {
"properties": {
"City": {
"type": "text"
}
}
}
}
}
}
用这些插入文档
POST my_index/_doc
{
"MDMGlobalData.City": "Chennai"
}
POST my_index/_doc
{
"MDMGlobalData.City": "Bangalore"
}
试图用这个排序
GET /my_index/_search
{
"sort": {
"MDMGlobalData.City": {
"order": "asc"
}
}
}
收到以下错误
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [MDMGlobalData.City] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
}
......
因此我更新了启用 fielddata 的映射
PUT my_index/_mapping
{
"properties": {
"MDMGlobalData": {
"properties": {
"City": {
"type": "text",
"fielddata": true
}
}
}
}
}
现在我搜索
GET /my_index/_search
{
"sort": {
"MDMGlobalData.City": {
"order": "asc"
}
}
}
它有效
推荐阅读
- javascript - 缺少) 参数列表后,当试图调用 JS 函数 onclick
- javascript - 单选按钮不隐藏/显示部分
- python - 在 Python 或 MATLAB 中对齐两个不同长度的二维向量
- stm32 - STM32F767ZI - STM32CubeIDE - 带 Max31856 的 SPI
- javascript - 问题序列化/反序列化剑道网格设置
- regex - 如何从正则表达式中的搜索中排除某些单词?
- python - 如何在特定的html代码中提取值
- c++ - 将 C++ 入口点覆盖为类的 STATIC 方法
- python - 如何将 2 个参数传递给 dict() 内置函数?
- c# - Firebase 实时数据库规则被拒绝权限