use of org.elasticsearch.index.reindex.BulkByScrollResponse in project pancm_project by xuwujing.
the class IpHandler method reindexByQuery.
/**
* @return Map
* @Author pancm
* @Description //重索引
* @Date 2019/3/21
* @Param []
*/
public static Map<String, Object> reindexByQuery(String index, String destIndex, QueryBuilder[] queryBuilders) throws IOException {
if (index == null || destIndex == null) {
return null;
}
Map<String, Object> map = new HashMap<>();
try {
// 创建索引复制请求并进行索引复制
ReindexRequest request = new ReindexRequest();
// 需要复制的索引
request.setSourceIndices(index);
/* 复制的目标索引 */
request.setDestIndex(destIndex);
if (queryBuilders != null) {
for (QueryBuilder queryBuilder : queryBuilders) {
request.setSourceQuery(queryBuilder);
}
}
// 表示如果在复制索引的时候有缺失的文档的话会进行创建,默认是index
request.setDestOpType("create");
// 如果在复制的过程中发现版本冲突,那么会继续进行复制
request.setConflicts("proceed");
// 设置复制文档的数量
// request.setSize(10);
// 设置一次批量处理的条数,默认是1000
// request.setSourceBatchSize(10000);
// 设置超时时间
request.setTimeout(TimeValue.timeValueMinutes(2));
// 同步执行
BulkByScrollResponse bulkResponse = client.reindex(request, RequestOptions.DEFAULT);
// 响应结果处理
map.put("time", bulkResponse.getTook().getMillis());
map.put("total", bulkResponse.getTotal());
map.put("createdDocs", bulkResponse.getCreated());
map.put("updatedDocs", bulkResponse.getUpdated());
} finally {
if (isAutoClose) {
close();
}
}
return map;
}
use of org.elasticsearch.index.reindex.BulkByScrollResponse in project vertigo by KleeGroup.
the class ESStatement method remove.
/**
* Supprime des documents.
* @param query Requete de filtrage des documents à supprimer
*/
void remove(final ListFilter query) {
Assertion.checkNotNull(query);
// -----
try {
final QueryBuilder queryBuilder = ESSearchRequestBuilder.translateToQueryBuilder(query);
final DeleteByQueryRequestBuilder deleteByQueryAction = DeleteByQueryAction.INSTANCE.newRequestBuilder(esClient).filter(queryBuilder);
deleteByQueryAction.source().setIndices(indexName).setTypes(typeName);
final BulkByScrollResponse response = deleteByQueryAction.get();
final long deleted = response.getDeleted();
LOGGER.debug("Removed {0} elements", deleted);
} catch (final SearchPhaseExecutionException e) {
final VUserException vue = new VUserException(SearchResource.DYNAMO_SEARCH_QUERY_SYNTAX_ERROR);
vue.initCause(e);
throw vue;
}
}
use of org.elasticsearch.index.reindex.BulkByScrollResponse in project gora by apache.
the class ElasticsearchStore method deleteByQuery.
@Override
public long deleteByQuery(Query<K, T> query) throws GoraException {
try {
BulkByScrollResponse bulkResponse;
if (query.getFields() != null && query.getFields().length < elasticsearchMapping.getFields().size()) {
UpdateByQueryRequest updateRequest = new UpdateByQueryRequest(elasticsearchMapping.getIndexName());
QueryBuilder matchDocumentsWithinRange = QueryBuilders.rangeQuery("gora_id").from(query.getStartKey()).to(query.getEndKey());
updateRequest.setQuery(matchDocumentsWithinRange);
// Create a script for deleting fields
StringBuilder toDelete = new StringBuilder();
String[] fieldsToDelete = query.getFields();
for (String field : fieldsToDelete) {
String elasticsearchField = elasticsearchMapping.getFields().get(field).getName();
toDelete.append(String.format(Locale.getDefault(), "ctx._source.remove('%s');", elasticsearchField));
}
// toDelete.deleteCharAt(toDelete.length() - 1);
updateRequest.setScript(new Script(ScriptType.INLINE, "painless", toDelete.toString(), Collections.emptyMap()));
bulkResponse = client.updateByQuery(updateRequest, RequestOptions.DEFAULT);
return bulkResponse.getUpdated();
} else {
DeleteByQueryRequest deleteRequest = new DeleteByQueryRequest(elasticsearchMapping.getIndexName());
QueryBuilder matchDocumentsWithinRange = QueryBuilders.rangeQuery("gora_id").from(query.getStartKey()).to(query.getEndKey());
deleteRequest.setQuery(matchDocumentsWithinRange);
bulkResponse = client.deleteByQuery(deleteRequest, RequestOptions.DEFAULT);
return bulkResponse.getDeleted();
}
} catch (IOException ex) {
throw new GoraException(ex);
}
}
use of org.elasticsearch.index.reindex.BulkByScrollResponse in project graylog2-server by Graylog2.
the class IndicesAdapterES7 method move.
@Override
public void move(String source, String target, Consumer<IndexMoveResult> resultCallback) {
final ReindexRequest request = new ReindexRequest();
request.setSourceIndices(source);
request.setDestIndex(target);
final BulkByScrollResponse result = client.execute((c, requestOptions) -> c.reindex(request, requestOptions));
final IndexMoveResult indexMoveResult = IndexMoveResult.create(Math.toIntExact(result.getTotal()), result.getTook().millis(), !result.getBulkFailures().isEmpty());
resultCallback.accept(indexMoveResult);
}
Aggregations