2013-12-10 47 views
2

我在Elasticsearch(0.90)API中遇到此錯誤,當我嘗試索引簡單的JSON文檔時。Elasticsearch錯誤:解析失敗,文檔爲空

下面的代碼:

TransportClient client = new TransportClient().addTransportAddress(new InetSocketTransportAddress("localhost", 9300)); 
String indexName = "searchwriter-" + FORMAT.format(System.currentTimeMillis()); 
client.prepareIndex(indexName, "trace", String.valueOf(id++)).setOpType(IndexRequest.OpType.INDEX).setSource(inputLine).execute().actionGet(); 

inputLine在上面的代碼不爲空。它的值低於

{"type":"MasterCard1","name":"Zaheen1"}

例外:

 
[2013-12-10 11:26:24,475][DEBUG][action.index    ] [Foxfire] [searchwriter-2013-12-10][0], node[Hamh7CPnQIqqp4pYA-DD9w], [P], s[STARTED]: Failed to execute [index {[searchwriter-2013- 
12-10][trace][2], source[_na_]}]                                         
org.elasticsearch.index.mapper.MapperParsingException: failed to parse, document is empty                          
     at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:530)                           
     at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:452)                           
     at org.elasticsearch.index.shard.service.InternalIndexShard.prepareIndex(InternalIndexShard.java:341)                     
     at org.elasticsearch.action.index.TransportIndexAction.shardOperationOnPrimary(TransportIndexAction.java:203)                   
     at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction.performOnPrimary(TransportShardReplicationOperationAction.java:533) 
     at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction$1.run(TransportShardReplicationOperationAction.java:418)    
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)                          
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)                          
     at java.lang.Thread.run(Thread.java:724)                                     

我GOOGLE了,但我不能找到原因。有任何想法嗎?

+0

應該輸入你正在發送的json文件中?你有沒有嘗試像使用ES示例一樣使用XContentBuilder設置源代碼? '''setSource()jsonBuilder() .startObject() .field(「user」,「kimchy」) .field(「postDate」,new Date()) .field(「message」,「Tryout Elastic搜索「) .endObject()'''Inputline是一個json的字符串,如果是的話,它需要被轉義嗎? – mconlin

回答

0

這應該工作。所以,我猜想inputLine不包含你認爲它包含的內容。嘗試用硬編碼的版本替換您的inputLine

client.prepareIndex(indexName, "trace", String.valueOf(id++)).setOpType(IndexRequest.OpType.INDEX).setSource("{\"type\":\"MasterCard1\",\"name\":\"Zaheen1\"}").execute().actionGet(); 

,看它是否解決了問題。

以防萬一,您是否在客戶端和服務器上使用相同版本的elasticsearch?

相關問題