elasticsearch text字段排序报错解决
来源:互联网 发布:android精品源码 编辑:程序博客网 时间:2024/05/22 00:49
elasticsearch text字段排序报错解决
使用elasticsearch 进行排序的时候,我们一般都会排序数字、日期。但是在排序text类型的时候就会出现错误。
GET xytest/sutdent/_search
{
"sort":[
{"region": {"order": "asc"}}
]
, "from": 0
, "size": 2
}
{
"sort":[
{"region": {"order": "asc"}}
]
, "from": 0
, "size": 2
}
结果如下:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [region] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "xytest",
"node": "6h-7wPJmQqWGfz6nbgqjjQ",
"reason": {
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [region] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."
}
}
],
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [region] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."
}
},
"status": 400
}
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [region] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "xytest",
"node": "6h-7wPJmQqWGfz6nbgqjjQ",
"reason": {
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [region] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."
}
}
],
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [region] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."
}
},
"status": 400
}
主要原因是:"Fielddata is disabled on text fields by default. Set fielddata=true on [region] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."
参考官方文档:
https://www.elastic.co/guide/en/elasticsearch/reference/current/fielddata.html
方案一:我们可以用region.keyword进行聚合,排序。用region用来查询。那么我们对我们的查询进行修改
GET xytest/sutdent/_search
{
"sort":[
{"region.keyword": {"order": "asc"}}
]
, "from": 0
, "size": 2
}
{
"sort":[
{"region.keyword": {"order": "asc"}}
]
, "from": 0
, "size": 2
}
修改后查询结果:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 6,
"max_score": null,
"hits": [
{
"_index": "xytest",
"_type": "sutdent",
"_id": "6",
"_score": null,
"_source": {
"sid": "00006",
"name": "牧琢杭",
"age": "26",
"region": "广东省 湛江市 赤坎区",
"grade": [
{
"数学": 80
},
{
"语文": 63
},
{
"英语": 90
}
]
},
"sort": [
"广东省 湛江市 赤坎区"
]
},
{
"_index": "xytest",
"_type": "sutdent",
"_id": "5",
"_score": null,
"_source": {
"sid": "00005",
"name": "范旭",
"age": "30",
"region": "新疆维吾尔自治区 和田地区 和田县",
"grade": [
{
"数学": 90
},
{
"语文": 69
},
{
"英语": 60
}
]
},
"sort": [
"新疆维吾尔自治区 和田地区 和田县"
]
}
]
}
}
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 6,
"max_score": null,
"hits": [
{
"_index": "xytest",
"_type": "sutdent",
"_id": "6",
"_score": null,
"_source": {
"sid": "00006",
"name": "牧琢杭",
"age": "26",
"region": "广东省 湛江市 赤坎区",
"grade": [
{
"数学": 80
},
{
"语文": 63
},
{
"英语": 90
}
]
},
"sort": [
"广东省 湛江市 赤坎区"
]
},
{
"_index": "xytest",
"_type": "sutdent",
"_id": "5",
"_score": null,
"_source": {
"sid": "00005",
"name": "范旭",
"age": "30",
"region": "新疆维吾尔自治区 和田地区 和田县",
"grade": [
{
"数学": 90
},
{
"语文": 69
},
{
"英语": 60
}
]
},
"sort": [
"新疆维吾尔自治区 和田地区 和田县"
]
}
]
}
}
方案二:这是region这个排序字段的fileddata为true。
PUT xytest/_mapping/sutdent
{
"properties": {
"region":{
"type": "text",
"fielddata": true
}
}
}
{
"properties": {
"region":{
"type": "text",
"fielddata": true
}
}
}
设置结果:
{
"acknowledged": true
}
"acknowledged": true
}
我们再次运行最开始的查询:
GET xytest/sutdent/_search
{
"sort":[
{"region": {"order": "asc"}}
]
, "from": 0
, "size": 2
}
{
"sort":[
{"region": {"order": "asc"}}
]
, "from": 0
, "size": 2
}
返回结果:
{
"took": 130,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 6,
"max_score": null,
"hits": [
{
"_index": "xytest",
"_type": "sutdent",
"_id": "6",
"_score": null,
"_source": {
"sid": "00006",
"name": "牧琢杭",
"age": "26",
"region": "广东省 湛江市 赤坎区",
"grade": [
{
"数学": 80
},
{
"语文": 63
},
{
"英语": 90
}
]
},
"sort": [
"东"
]
},
{
"_index": "xytest",
"_type": "sutdent",
"_id": "4",
"_score": null,
"_source": {
"sid": "00004",
"name": "符龙",
"age": "37",
"region": "河北省 保定市 清苑县",
"grade": [
{
"数学": 80
},
{
"语文": 79
},
{
"英语": 69
}
]
},
"sort": [
"保"
]
}
]
}
}
"took": 130,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 6,
"max_score": null,
"hits": [
{
"_index": "xytest",
"_type": "sutdent",
"_id": "6",
"_score": null,
"_source": {
"sid": "00006",
"name": "牧琢杭",
"age": "26",
"region": "广东省 湛江市 赤坎区",
"grade": [
{
"数学": 80
},
{
"语文": 63
},
{
"英语": 90
}
]
},
"sort": [
"东"
]
},
{
"_index": "xytest",
"_type": "sutdent",
"_id": "4",
"_score": null,
"_source": {
"sid": "00004",
"name": "符龙",
"age": "37",
"region": "河北省 保定市 清苑县",
"grade": [
{
"数学": 80
},
{
"语文": 79
},
{
"英语": 69
}
]
},
"sort": [
"保"
]
}
]
}
}
1 0
- elasticsearch text字段排序报错解决
- 解决ElasticSearch启动报错
- MySQL多Text字段报8126错误(解决过程)
- MySQL多Text字段报8126错误(解决过程)
- ElasticSearch字段排序
- 解决 AFNetWorking报错 text/html
- 解决排序规则报错
- elasticsearch解决某一字段值等于某字符串时优先排序问题
- ElasticSearch path.home is not configured报错解决
- Linux解决安装ElasticSearch启动报错方法
- ElasticSearch java API 按照某个字段排序
- Elasticsearch搜索并按照某字段排序
- 运行elasticsearch报错
- ElasticSearch报错
- ElasticSearch报错
- ElasticSearch 启动报错
- elasticsearch启动报错
- 解决Mysql存入大量TEXT类型的数据报错
- GameKit 蓝牙
- PHP 替换文章关键字,链接 只替换一次(避免重复替换)
- TFS发布计划发送到钉钉消息群
- 关于ES6中的promise用法以及在ajax中的应用
- MySQL性能优化的最佳20+条经验
- elasticsearch text字段排序报错解决
- ngnix反向代理tomcat,动静态分离
- ubuntu16.04环境下部署jdk
- struts2校验(2)
- redis的配置(安装、启动、本机与虚拟机的redis的连接)
- Qt实现读取显示obj文件——绘制数据
- Linux Runtime PM介绍
- 有关DBLINK操作的语句执行机制及优化方式
- R 语言中的S3系统(笔记)