本文整理汇总了Java中org.elasticsearch.action.bulk.BulkResponse.hasFailures方法的典型用法代码示例。如果您正苦于以下问题:Java BulkResponse.hasFailures方法的具体用法?Java BulkResponse.hasFailures怎么用?Java BulkResponse.hasFailures使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.action.bulk.BulkResponse
的用法示例。
在下文中一共展示了BulkResponse.hasFailures方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insertThreadObjectToES
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
/**
* TODO:线程分析数据的存储
*
* @param result
*/
private void insertThreadObjectToES(List<JavaThreadObject> result) {
if (this.log.isDebugEnable()) {
this.log.debug(this, "ThreadObjectToES is :" + JSONHelper.toString(result));
}
BulkRequestBuilder bulkRequest = client.getClient().prepareBulk();
for (JavaThreadObject item : result) {
pushDataToBulkRequest(item, bulkRequest);
}
BulkResponse bulkResponse = bulkRequest.get();
if (bulkResponse.hasFailures()) {
log.err(this, "INSERT ThreadAnalysis Data to ES FAIL: " + bulkResponse.buildFailureMessage());
}
}
示例2: batchPersistence
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
@Override public void batchPersistence(List<?> batchCollection) {
BulkRequestBuilder bulkRequest = getClient().prepareBulk();
logger.debug("bulk data size: {}", batchCollection.size());
if (CollectionUtils.isNotEmpty(batchCollection)) {
batchCollection.forEach(builder -> {
if (builder instanceof IndexRequestBuilder) {
bulkRequest.add((IndexRequestBuilder)builder);
}
if (builder instanceof UpdateRequestBuilder) {
bulkRequest.add((UpdateRequestBuilder)builder);
}
});
BulkResponse bulkResponse = bulkRequest.execute().actionGet();
if (bulkResponse.hasFailures()) {
logger.error(bulkResponse.buildFailureMessage());
}
}
}
示例3: deleteES
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
private static void deleteES(Client client) {
BulkRequestBuilder bulkRequest = client.prepareBulk();
SearchResponse response = client.prepareSearch(index).setTypes(type)
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(QueryBuilders.matchAllQuery())
.setFrom(0).setSize(20).setExplain(true).execute().actionGet();
System.out.println("length: " + response.getHits().getHits().length);
if (response.getHits().getHits().length != 0) {
for (SearchHit hit : response.getHits()) {
String id = hit.getId();
System.out.println("id: " + id);
bulkRequest.add(client.prepareDelete(index, type, id).request());
}
BulkResponse bulkResponse = bulkRequest.get();
if (bulkResponse.hasFailures()) {
for (BulkItemResponse item : bulkResponse.getItems()) {
System.out.println(item.getFailureMessage());
}
} else {
System.out.println("delete ok");
}
} else {
System.out.println("delete ok");
}
}
示例4: createIndex
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
/**
* 创建索引
*
* @param datas
* @param indexType
*/
public static <T extends IdAble> void createIndex(List<T> datas, IndexType indexType) {
// 批量处理request
BulkRequestBuilder bulkRequest = EsClientManager.getClient().prepareBulk();
byte[] json;
for (T t : datas) {
json = EsDataUtil.toBytes(t);
bulkRequest.add(new IndexRequest(esprop.getIndice(), indexType.getDataName(), t.getId() + "").source(json));
}
// 执行批量处理request
BulkResponse bulkResponse = bulkRequest.get();
// 处理错误信息
if (bulkResponse.hasFailures()) {
LOGGER.warn("====================批量创建索引过程中出现错误 下面是错误信息==========================");
long count = 0L;
for (BulkItemResponse bulkItemResponse : bulkResponse) {
LOGGER.warn("类型 " + indexType.getDataName() + " 发生错误的 索引id为 : " + bulkItemResponse.getId() + " ,错误信息为:" + bulkItemResponse.getFailureMessage());
count++;
}
LOGGER.warn("====================批量创建索引过程中出现错误 上面是错误信息 共有: " + count + " 条记录==========================");
}
}
示例5: bulkUpdate
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
public static void bulkUpdate(Client client ) throws IOException, InterruptedException, ExecutionException {
BulkRequestBuilder req = client.prepareBulk();
req.add(client.prepareIndex("search_test","article","2")
.setSource(jsonBuilder()
.startObject()
.field("title","bulk title 02 04-05")));
req.add(client.prepareIndex("search_test","article","3")
.setSource(jsonBuilder()
.startObject()
.field("title","bulk title 03 04-05")));
req.add(client.prepareIndex("search_test","article","4")
.setSource(jsonBuilder()
.startObject()
.field("title","bulk title 04 04-05")));
BulkResponse res = req.execute().actionGet();
if (res.hasFailures()){
System.out.println("Error");
} else {
System.out.println("Done");
}
client.close();
}
示例6: insert
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
@Override
public void insert(List<BucketOwner> bucketOwners, Date collectionTime) {
if (bucketOwners != null && !bucketOwners.isEmpty()) {
BulkRequestBuilder requestBuilder = elasticClient.prepareBulk();
// Generate JSON for object buckets info
for (BucketOwner bucketOwner : bucketOwners) {
XContentBuilder objectBucketBuilder = toJsonFormat(bucketOwner, collectionTime);
IndexRequestBuilder request = elasticClient.prepareIndex().setIndex(bucketownerIndexDayName)
.setType(BUCKET_OWNER_INDEX_TYPE).setSource(objectBucketBuilder);
requestBuilder.add(request);
}
BulkResponse bulkResponse = requestBuilder.execute().actionGet();
int items = bulkResponse.getItems().length;
LOGGER.info("Took " + bulkResponse.getTookInMillis() + " ms to index [" + items + "] items in ElasticSearch"
+ "index: " + bucketownerIndexDayName + " index type: " + BUCKET_OWNER_INDEX_TYPE);
if (bulkResponse.hasFailures()) {
LOGGER.error("Failures occured while items in ElasticSearch " + "index: " + bucketownerIndexDayName
+ " index type: " + BUCKET_OWNER_INDEX_TYPE);
}
}
}
示例7: prepareData
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
private static void prepareData(IndicesAdminClient indicesAdminClient) throws InterruptedException {
BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
//批量添加
for (int i = 0; i < 1000; i++) {
ItemInfo iteminfo=new ItemInfo(i,"商品"+i, new Random().nextFloat(),new Date());
// 当opType是Index时,如果文档id存在,更新文档,否则创建文档 当opType是Create,如果文档id存在,抛出文档存在的错误 *
IndexRequestBuilder indexRequestBuilder = client.prepareIndex(INDEX_NAME_v1, INDEX_TYPE).setId(i+"").setSource(JSONObject.toJSONString(iteminfo)).setOpType(IndexRequest.OpType.INDEX);
bulkRequestBuilder.add(indexRequestBuilder);
//数据日期不一样
}
BulkResponse bulkResponse = bulkRequestBuilder.execute().actionGet();
if (bulkResponse.hasFailures()) {
log.error("bulk index error:{}",bulkResponse.buildFailureMessage());
} else {
log.info("index docs : {}" , bulkResponse);
}
}
示例8: bulkIndex
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
private void bulkIndex(String indexType, JsonNode data) {
if (data.size() == 0) {
return;
}
if (uniqueFields.size() > 0) {
Set<String> keys = new HashSet<>();
ArrayNode uniqued = Json.newArray();
for (JsonNode point : data) {
String key = FeatureExtractorUtilities.composeConcatenatedKey(point, dataFields);
if (!keys.contains(key)) {
keys.add(key);
uniqued.add(point);
}
}
data = uniqued;
}
BulkResponse resp = elasticSearchService.bulkIndex(elasticSearchIndex, indexType, data);
if (resp.hasFailures()) {
throw new BadRequestException(resp.buildFailureMessage());
}
}
示例9: bulkDelete
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
private void bulkDelete(String indexType, JsonNode data) {
SearchHits hits = elasticSearchService
.searchHitsByKeys(elasticSearchIndex, indexType, uniqueFields, uniqueFields, data);
List<String> ids = new ArrayList<>();
for (SearchHit hit : hits.getHits()) {
if (hit != null) {
ids.add(hit.getId());
}
}
if (ids.size() == 0) {
return;
}
BulkResponse resp = elasticSearchService.bulkDelete(elasticSearchIndex, indexType, ids);
if (resp.hasFailures()) {
throw new BadRequestException(resp.buildFailureMessage());
}
}
示例10: add
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
public BulkResponse add(String indexName, String sensorType, Iterable<String> docs)
throws IOException {
BulkRequestBuilder bulkRequest = getClient().prepareBulk();
for (String doc : docs) {
IndexRequestBuilder indexRequestBuilder = getClient()
.prepareIndex(indexName, sensorType + "_doc");
indexRequestBuilder = indexRequestBuilder.setSource(doc);
Map<String, Object> esDoc = JSONUtils.INSTANCE
.load(doc, new TypeReference<Map<String, Object>>() {
});
indexRequestBuilder.setId((String) esDoc.get(Constants.GUID));
Object ts = esDoc.get("timestamp");
if (ts != null) {
indexRequestBuilder = indexRequestBuilder.setTimestamp(ts.toString());
}
bulkRequest.add(indexRequestBuilder);
}
BulkResponse response = bulkRequest.execute().actionGet();
if (response.hasFailures()) {
throw new IOException(response.buildFailureMessage());
}
return response;
}
示例11: bulkDelete
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
@Override
public void bulkDelete(BulkDeleteRequest request) {
if (request.ids == null || request.ids.isEmpty()) throw Exceptions.error("request.ids must not be empty");
StopWatch watch = new StopWatch();
String index = request.index == null ? this.index : request.index;
BulkRequestBuilder builder = client().prepareBulk();
for (String id : request.ids) {
builder.add(client().prepareDelete(index, type, id));
}
long esTookTime = 0;
try {
BulkResponse response = builder.get();
esTookTime = response.getTook().nanos();
if (response.hasFailures()) throw new SearchException(response.buildFailureMessage());
} catch (ElasticsearchException e) {
throw new SearchException(e); // due to elastic search uses async executor to run, we have to wrap the exception to retain the original place caused the exception
} finally {
long elapsedTime = watch.elapsedTime();
ActionLogContext.track("elasticsearch", elapsedTime, 0, request.ids.size());
logger.debug("bulkDelete, index={}, type={}, size={}, esTookTime={}, elapsedTime={}", index, type, request.ids.size(), esTookTime, elapsedTime);
checkSlowOperation(elapsedTime);
}
}
示例12: processBulkRequests
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
protected BulkResponse processBulkRequests(final List<IndexRequestBuilder> requests)
{
if (requests.size() > 0)
{
final BulkRequestBuilder bulkRequest = searchClientService.getClient().prepareBulk();
for (final IndexRequestBuilder indexRequestBuilder : requests)
{
bulkRequest.add(indexRequestBuilder);
}
logger.debug("Executing bulk index request for size:" + requests.size());
final BulkResponse bulkResponse = bulkRequest.execute().actionGet();
logger.debug("Bulk operation data index response total items is:" + bulkResponse.getItems().length);
if (bulkResponse.hasFailures())
{
// process failures by iterating through each bulk response item
logger.error("bulk operation indexing has failures:" + bulkResponse.buildFailureMessage());
}
return bulkResponse;
}
else
{
logger.debug("Executing bulk index request for size: 0");
return null;
}
}
示例13: processBulkRequests
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
protected BulkResponse processBulkRequests(
final List<IndexRequestBuilder> requests) {
if (requests.size() > 0) {
final BulkRequestBuilder bulkRequest = searchClientService
.getClient().prepareBulk();
for (final IndexRequestBuilder indexRequestBuilder : requests) {
bulkRequest.add(indexRequestBuilder);
}
logger.debug("Executing bulk index request for size:"
+ requests.size());
final BulkResponse bulkResponse = bulkRequest.execute().actionGet();
logger.debug("Bulk operation data index response total items is:"
+ bulkResponse.getItems().length);
if (bulkResponse.hasFailures()) {
// process failures by iterating through each bulk response item
logger.error("bulk operation indexing has failures:"
+ bulkResponse.buildFailureMessage());
}
return bulkResponse;
} else {
logger.debug("Executing bulk index request for size: 0");
return null;
}
}
示例14: testBulk
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
@Test
public void testBulk() throws Exception {
BulkRequestBuilder bulkRequest = client.prepareBulk();
// either use client#prepare, or use Requests# to directly build
// index/delete requests
bulkRequest.add(client.prepareIndex("twitter", "tweet", "1").setSource(XContentFactory.jsonBuilder().startObject().field("user", "kimchy")
.field("postDate", new Date()).field("message", "trying out Elasticsearch").endObject()));
bulkRequest.add(client.prepareIndex("twitter", "tweet", "2").setSource(XContentFactory.jsonBuilder().startObject().field("user", "kimchy")
.field("postDate", new Date()).field("message", "another post").endObject()));
BulkResponse bulkResponse = bulkRequest.get();
if (bulkResponse.hasFailures()) {
// process failures by iterating through each bulk response item
}
}
示例15: saveBatch
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
public List<T> saveBatch(List<T> entities) throws Exception {
List<T> result = new ArrayList<>();
BulkRequestBuilder bulkRequest = client.prepareBulk();
for (T entity : entities) {
String id = mapping.id(entity);
String index = mapping.index(entity);
String type = mapping.type(entity);
String source = mapping.toDocument(entity);
bulkRequest.add(client.prepareIndex(index, type, id).setSource(source));
result.add(entity);
}
BulkResponse bulkResponse = bulkRequest.execute().actionGet();
if (bulkResponse.hasFailures()) {
log.error("Bulk ingest has errors");
}
return result;
}