發(fā)生緣由
- 學習ES中Java HighLevel Rest Client客戶端API
運行環(huán)境
- elasticsearch版本:7.12.1
- jdk版本:jdk-8
- 電腦系統(tǒng):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 字節(jié)或壓縮的 xcontent 字節(jié)上面調(diào)用
根據(jù)報錯原因可以將錯誤定位至HotelDemoApplicationTests.java:33
行,代碼如下:
@Test
void createHotelIndex() throws IOException {
// 1.創(chuàng)建Request對象
CreateIndexRequest request = new CreateIndexRequest("hotel");
// 2.準備請求的參數(shù) DSL語句
// 33行 報錯
request.source(MAPPING_TEMPLATE, XContentType.JSON);
// 3.發(fā)送請求
client.indices().create(request, RequestOptions.DEFAULT);
}
那么就可以將報錯信息轉(zhuǎn)為人話了:語句的類型不是JSON風格的或者JSON格式化錯誤了。
定位MAPPING_TEMPLATE
,代碼如下:文章來源:http://www.zghlxwxcb.cn/news/detail-504902.html
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" +
。將其刪去即可。文章來源地址http://www.zghlxwxcb.cn/news/detail-504902.html
到了這里,關(guān)于ES:Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!