问题描述
用elasticsearch批量创建索引时候会报以下错误[0]:index[myshop_portal],type[type-product],id[1],message[UnavailableShardsException[[myshop_portal][2]Primaryshardisnotactiveorisn'tassignedisaknownnode.Timeout:[1m],request:org.elasticsearch.action.bulk.BulkShardRequest@47359fdc]][2]:index[myshop_portal],type[type-product],id[3],message[UnavailableShardsException[[myshop_portal][4]Primaryshardisnotactiveorisn'tassignedisaknownnode.Timeout:[1m],request:org.elasticsearch.action.bulk.BulkShardRequest@2e0a2298]][3]:index[myshop_portal],type[type-product],id[4],message[UnavailableShardsException[[myshop_portal][0]Primaryshardisnotactiveorisn'tassignedisaknownnode.Timeout:[1m],request:org.elasticsearch.action.bulk.BulkShardRequest@7b5c733d]][5]:index[myshop_portal],type[type-product],id[13],message[UnavailableShardsException[[myshop_portal][2]Primaryshardisnotactiveorisn'tassignedisaknownnode.Timeout:[1m],request:org.elasticsearch.action.bulk.BulkShardRequest@47359fdc]]但是用junit跑就不出错....publicvoidbulkIndex(List<SearchDocument>searchDocuments){try{Nodenode=NodeBuilder.nodeBuilder().node();client=node.client();BulkRequestBuilderbulkRequest=client.prepareBulk();for(SearchDocumentsearchDoc:searchDocuments){IndexRequestBuilderindexRequest=this.prepareIndexRequest(searchDoc);bulkRequest.add(indexRequest);}BulkResponsebulkResponse=bulkRequest.execute().actionGet();if(bulkResponse.hasFailures()){thrownewElasticSearchException(bulkResponse.buildFailureMessage());}}catch(Exceptione){e.printStackTrace();}finally{if(client!=null){client.close();}}}privateIndexRequestBuilderprepareIndexRequest(SearchDocumentsearchDoc)throwsException{Stringid=searchDoc.getId();Stringsource=searchDoc.getSource();IndexRequestBuilderindexRequestBuilder=null;if(source!=null){System.out.println(source);indexRequestBuilder=client.prepareIndex(searchDoc.getIndexName(),searchDoc.getType(),id).setSource(source);}else{thrownewElasticSearchException("objectorsourceisnull,failedtoindexthedocument[id:"+searchDoc.getId()+"]");}returnindexRequestBuilder;}