Compressor detection can only be called on some ……

今天写的ES客户端测试的文件里一个方法报错,方法体如下:

public IndexResponse createIndex(String indexName, String type,
			String jsonArray) {

		IndexRequestBuilder builder = client.prepareIndex(indexName, type).setSource(jsonArray);
		
		IndexResponse response = builder.execute().actionGet();
		return response;

	}

报错内容如下:

Exception in thread "main" MapperParsingException[failed to parse]; nested: NotSerializableExceptionWrapper[not_x_content_exception: Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes];
     at org.elasticsearch.index.mapper.DocumentParser.parseDocument(DocumentParser.java:154)
     at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:309)
     at org.elasticsearch.index.shard.IndexShard.prepareCreate(IndexShard.java:529)
     at org.elasticsearch.index.shard.IndexShard.prepareCreateOnPrimary(IndexShard.java:506)
     at org.elasticsearch.action.index.TransportIndexAction.prepareIndexOperationOnPrimary(TransportIndexAction.java:215)
     at org.elasticsearch.action.index.TransportIndexAction.executeIndexRequestOnPrimary(TransportIndexAction.java:224)
     at org.elasticsearch.action.index.TransportIndexAction.shardOperationOnPrimary(TransportIndexAction.java:158)
     at org.elasticsearch.action.index.TransportIndexAction.shardOperationOnPrimary(TransportIndexAction.java:66)
     at org.elasticsearch.action.support.replication.TransportReplicationAction$PrimaryPhase.doRun(TransportReplicationAction.java:639)
     at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
     at org.elasticsearch.action.support.replication.TransportReplicationAction$PrimaryOperationTransportHandler.messageReceived( TransportReplicationAction.java:279)
     at org.elasticsearch.action.support.replication.TransportReplicationAction$PrimaryOperationTransportHandler.messageReceived( TransportReplicationAction.java:271)
     at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:75)
     at org.elasticsearch.transport.TransportService$4.doRun(TransportService.java:376)
     at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
     at java.lang.Thread.run( Thread.java:745)
Caused by: NotSerializableExceptionWrapper[not_x_content_exception: Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes]
     at org.elasticsearch.common.compress.CompressorFactory.compressor(CompressorFactory.java:85)
     at org.elasticsearch.common.xcontent.XContentHelper.createParser(XContentHelper.java:50)
     at org.elasticsearch.index.mapper.DocumentParser.parseDocument(DocumentParser.java:90)
     ... 17 more

在我这里造成这一异常  的原因是传递的参数jsonArray格式不对,我打印了下jsonArray,格式如下:

[{"name":"hui1","salary":10000.39982635574,"age":8},
{"name":"hui2","salary":10000.160206564933,"age":11},
{"name":"hui3","salary":10000.417013742277,"age":28},
{"name":"hui4","salary":10000.26786620842,"age":7}]
这里正确的格式应该是这样:
{"name":"hui1","salary":10000.39982635574,"age":8}

即便将原来以 "[" 开关的jsonArray去年“[”,改成这样:

{"name":"hui1","salary":10000.39982635574,"age":8},
{"name":"hui2","salary":10000.160206564933,"age":11},
{"name":"hui3","salary":10000.417013742277,"age":28},
{"name":"hui4","salary":10000.26786620842,"age":7}

也一样会报错。

你可能感兴趣的:(Compressor detection can only be called on some ……)