elasticsearch批量建索引出错

Amacoder 2015-02-15 07:23:48
用elasticsearch批量创建索引时候会报以下错误
[0]: index [myshop_portal], type [type-product], id [1], message [UnavailableShardsException[[myshop_portal][2] Primary shard is not active or isn't assigned is a known node. Timeout: [1m], request: org.elasticsearch.action.bulk.BulkShardRequest@47359fdc]]
[2]: index [myshop_portal], type [type-product], id [3], message [UnavailableShardsException[[myshop_portal][4] Primary shard is not active or isn't assigned is a known node. Timeout: [1m], request: org.elasticsearch.action.bulk.BulkShardRequest@2e0a2298]]
[3]: index [myshop_portal], type [type-product], id [4], message [UnavailableShardsException[[myshop_portal][0] Primary shard is not active or isn't assigned is a known node. Timeout: [1m], request: org.elasticsearch.action.bulk.BulkShardRequest@7b5c733d]]
[5]: index [myshop_portal], type [type-product], id [13], message [UnavailableShardsException[[myshop_portal][2] Primary shard is not active or isn't assigned is a known node. Timeout: [1m], request: org.elasticsearch.action.bulk.BulkShardRequest@47359fdc]]

但是用junit跑就不出错....

public void bulkIndex(List<SearchDocument> searchDocuments) {
try {
Node node = NodeBuilder.nodeBuilder().node();
client = node.client();
BulkRequestBuilder bulkRequest = client.prepareBulk();
for (SearchDocument searchDoc : searchDocuments) {
IndexRequestBuilder indexRequest = this.prepareIndexRequest(searchDoc);
bulkRequest.add(indexRequest);
}
BulkResponse bulkResponse = bulkRequest.execute().actionGet();
if (bulkResponse.hasFailures()) {
throw new ElasticSearchException(bulkResponse.buildFailureMessage());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (client != null) {
client.close();
}
}
}

private IndexRequestBuilder prepareIndexRequest(SearchDocument searchDoc) throws Exception {
String id = searchDoc.getId();
String source = searchDoc.getSource();
IndexRequestBuilder indexRequestBuilder = null;
if (source != null) {
System.out.println(source);
indexRequestBuilder = client.prepareIndex(searchDoc.getIndexName(), searchDoc.getType(), id).setSource(source);
} else {
throw new ElasticSearchException("object or source is null, failed to index the document [id: " + searchDoc.getId() + "]");
}
return indexRequestBuilder;
}

...全文
1239 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaoxu_2013 2017-02-17
  • 打赏
  • 举报
回复
解决了吗?我也遇到类似问题。

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧