ES:Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes
发生缘由
-
学习ES中Java HighLevel Rest Client客户端API
运行环境
-
elasticsearch版本:7.12.1
-
jdk版本:jdk-8
-
电脑系统:win10
-
Idea版本:2021.2
报错信息
org.elasticsearch.common.compress.NotXContentException: Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes
at org.elasticsearch.common.compress.CompressorFactory.compressor(CompressorFactory.java:42)
at org.elasticsearch.common.xcontent.XContentHelper.convertToMap(XContentHelper.java:108)
at org.elasticsearch.client.indices.CreateIndexRequest.source(CreateIndexRequest.java:276)
at org.elasticsearch.client.indices.CreateIndexRequest.source(CreateIndexRequest.java:257)
at com.linxuan.hotel.HotelDemoApplicationTests.createHotelIndex(HotelDemoApplicationTests.java:33)
at java.util.ArrayList.forEach(ArrayList.java:1249)
at java.util.ArrayList.forEach(ArrayList.java:1249)
分析排查
-
Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes
-
压缩器检测只能在某些 xcontent 字节或压缩的 xcontent 字节上面调用
根据报错原因可以将错误定位至HotelDemoApplicationTests.java:33
行,代码如下:
那么就可以将报错信息转为人话了:语句的类型不是JSON风格的或者JSON格式化错误了。
定位MAPPING_TEMPLATE
,代码如下:
public static final String MAPPING_TEMPLATE = "PUT /hotel\n" +
"{\n" +
" \"mappings\": {\n" +
" \"properties\": {\n" +
" \"id\": {\n" +
" \"type\": \"keyword\"\n" +
" },\n" +
" \"name\":{\n" +
" \"type\": \"text\",\n" +
" \"analyzer\": \"ik_max_word\",\n" +
" \"copy_to\": \"all\"\n" +
" },\n" +
" \"address\":{\n" +
" \"type\": \"keyword\",\n" +
" \"index\": false\n" +
" },\n" +
" \"all\":{\n" +
" \"type\": \"text\",\n" +
" \"analyzer\": \"ik_max_word\"\n" +
" }\n" +
" }\n" +
" }\n" +
"}\n";
OK,原因找到了,因为添加了这一点代码:"PUT /hotel\n" +
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)