项目环境:springboot2.0.3 、elasticsearch5.6.10
先直接看报错信息:va.lang.IllegalArgumentException: Fielddata is disabled on text fields by default. Set fielddata=true on [username] 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.
前景:博主需要对username来进行聚类统计分析,查找到热门用户的列表信息,就是elasticsearch的统计功能。但是呢报错信息一直提示我要对该字段设置 fielddata=true,但是我明明已经设置了,如下所示。
但是我程序去组合条件查询时一直报错,所以只能着手解决问题。
1. 首先去使用elasticsearch-head-master项目来可视化管理elastsearch的索引(具体怎么搭建可以百度查询,该项目在github
上管理,查询elasticsearch-head即可得到), blog是我创建的索引的名字
2.查看索引的信息,如下查看
不看不知道,一看吓一跳,设置的fielddata=true 呢,看来没有设置成功
3.居然没成功,那只能使用原生的elasticsearch的API来进行设置了
请求方式:PUT
路径:ip地址:9200/索引名/_mapping/文档类型/?pretty
参数(json):
{"文档类型":
{"properties":
{"你要设置的字段名":
{"type":"text","fielddata":true}
}
}
}
返回结果:true
让我们再看索引的信息,就能看到fielddata:rue了