hadoop - 带有排序关键字的 Elasticsearch 查询参数
问题描述
我一直在使用 ES 5.4.0 版本并创建了索引和文档(学生数据)。当我根据年龄进行搜索时,_search 端点正在返回值,并且输出符合预期。对 name desc 选项做了同样的事情。我得到以下异常
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [name] 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."
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "students",
"node": "MESiRCvSSgqMNWEVwMevMg",
"reason": {
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [name] 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."
可能是什么原因。根据日志,我必须添加fileddata = true。这背后的任何原因。
http://localhost:9200/students/data/_search?q=montana&sort=age:desc - 工作正常。
http://localhost:9200/students/data/_search?q=montana&sort=name:desc - 不工作
http://localhost:9200/students/data/_search?q=montana&sort=name:desc&fielddata=true - 添加字段数据 - 不工作
// http://localhost:9200/students ?
{
"students": {
"aliases": {
},
"mappings": {
"data": {
"properties": {
"age": {
"type": "long"
},
"city": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"company": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"email": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"gender": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"phone": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"state": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"street": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
},
"settings": {
"index": {
"creation_date": "1530174012103",
"number_of_shards": "5",
"number_of_replicas": "1",
"uuid": "PrtajDL0SwS-tTX7Gm_YQw",
"version": {
"created": "5040099"
},
"provided_name": "students"
}
}
}
}
解决方案
您不能对text
字段进行排序(可以,但结果没有意义),但是,您可以对keyword
字段进行排序,因此以下查询将起作用:
http://localhost:9200/students/data/_search?q=montana&sort=name.keyword:desc
^
|
add this
推荐阅读
- css - 固定位置不会平移到地图的中心
- php - 如何从产品图像 EXIF 元标题中设置产品名称(帖子标题)
- angular - Angular 6:发送经过身份验证的请求
- python - 使用AND减少python ndarray中的布尔值
- python - 在 Python 中取消计时器
- java - JTextArea 和 JButton。将焦点设置在按钮上
- javascript - 用jquery拖放(一个工具箱和一个报表窗口)
- asp.net-core - Microsoft Distrubted Redis Cache - 根据模式获取密钥
- python-3.x - 为什么这个 Python 脚本不会用另一个变量替换一个变量?
- javascript - 下拉列表和 Javascript