Elasticsearch 대량 업데이트 방법.

1419 단어 ElasticSearch
ElasticSearch 대량 업데이트:
public void bulkUpdate(List queries) {
        BulkRequestBuilder bulkRequest = this.client.prepareBulk();
        Iterator bulkResponse = queries.iterator();

        while(bulkResponse.hasNext()) {
            UpdateQuery failedDocuments = (UpdateQuery)bulkResponse.next();
            bulkRequest.add(this.prepareUpdate(failedDocuments));
        }

        BulkResponse var9 = (BulkResponse)bulkRequest.execute().actionGet();
        if(var9.hasFailures()) {
            HashMap var10 = new HashMap();
            BulkItemResponse[] var5 = var9.getItems();
            int var6 = var5.length;

            for(int var7 = 0; var7 < var6; ++var7) {
                BulkItemResponse item = var5[var7];
                if(item.isFailed()) {
                    var10.put(item.getId(), item.getFailureMessage());
                }
            }

            throw new ElasticsearchException("Bulk indexing has failures. Use ElasticsearchException.getFailedDocuments() for detailed messages [" + var10 + "]", var10);
        }
    }
public class UpdateQuery {
    private String id;  // ES ID.
    private UpdateRequest updateRequest;
    private String indexName; // index ,  .
    private String type;  // .
    private Class clazz;  // , javabean, ES javabean , json .
    private boolean doUpsert;
	}

좋은 웹페이지 즐겨찾기