项目环境: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,但是我明明已经设置了,如下所示。

关于springboot整合elasticsearch5.6无法设置fielddata=true来进行聚类的解决方案

 

但是我程序去组合条件查询时一直报错,所以只能着手解决问题。

1.  首先去使用elasticsearch-head-master项目来可视化管理elastsearch的索引(具体怎么搭建可以百度查询,该项目在github

上管理,查询elasticsearch-head即可得到),   blog是我创建的索引的名字

关于springboot整合elasticsearch5.6无法设置fielddata=true来进行聚类的解决方案

 

2.查看索引的信息,如下查看

关于springboot整合elasticsearch5.6无法设置fielddata=true来进行聚类的解决方案

不看不知道,一看吓一跳,设置的fielddata=true 呢,看来没有设置成功

关于springboot整合elasticsearch5.6无法设置fielddata=true来进行聚类的解决方案

 

3.居然没成功,那只能使用原生的elasticsearch的API来进行设置了

请求方式:PUT

路径:ip地址:9200/索引名/_mapping/文档类型/?pretty

参数(json):

{"文档类型":
    {"properties":
        {"你要设置的字段名":
            {"type":"text","fielddata":true}
        }  
    } 
}

关于springboot整合elasticsearch5.6无法设置fielddata=true来进行聚类的解决方案

 

返回结果:true

关于springboot整合elasticsearch5.6无法设置fielddata=true来进行聚类的解决方案

让我们再看索引的信息,就能看到fielddata:rue了

关于springboot整合elasticsearch5.6无法设置fielddata=true来进行聚类的解决方案

*************然后再做聚类操作时就不会出现报错了,哈哈哈*****************************

相关文章:

  • 2022-12-23
  • 2021-12-01
  • 2021-11-27
  • 2021-12-05
  • 2021-10-09
  • 2021-08-01
  • 2022-03-08
  • 2021-06-20
猜你喜欢
  • 2022-12-23
  • 2021-10-02
  • 2021-05-02
  • 2021-09-01
  • 2021-12-05
  • 2021-03-31
  • 2021-09-17
相关资源
相似解决方案