本文整理汇总了Java中org.elasticsearch.action.deletebyquery.DeleteByQueryResponse类的典型用法代码示例。如果您正苦于以下问题:Java DeleteByQueryResponse类的具体用法?Java DeleteByQueryResponse怎么用?Java DeleteByQueryResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DeleteByQueryResponse类属于org.elasticsearch.action.deletebyquery包,在下文中一共展示了DeleteByQueryResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteByQuery
import org.elasticsearch.action.deletebyquery.DeleteByQueryResponse; //导入依赖的package包/类
public DeleteByQueryResponse deleteByQuery(String query, String backendId, String... types) {
Check.notNullOrEmpty(backendId, "backendId");
if (Strings.isNullOrEmpty(query))
query = Json8.objectBuilder().object("query").object("match_all").toString();
String[] indices = types == null ? toIndices(backendId) : toAliases(backendId, types);
DeleteByQueryRequest delete = new DeleteByQueryRequest(indices)//
.timeout(new TimeValue(60000))//
.source(query);
try {
return Start.get().getElasticClient().execute(DeleteByQueryAction.INSTANCE, delete).get();
} catch (ExecutionException | InterruptedException e) {
throw Exceptions.runtime(e);
}
}
示例2: deleteSearchForType
import org.elasticsearch.action.deletebyquery.DeleteByQueryResponse; //导入依赖的package包/类
@Delete("/:type")
@Delete("/:type/")
public Payload deleteSearchForType(String type, String query, Context context) {
Credentials credentials = SpaceContext.checkAdminCredentials();
if (DataAccessControl.check(credentials, type, DataPermission.delete_all)) {
boolean refresh = context.query().getBoolean(PARAM_REFRESH, true);
DataStore.get().refreshType(refresh, credentials.backendId(), type);
DeleteByQueryResponse response = Start.get().getElasticClient()//
.deleteByQuery(query, credentials.backendId(), type);
return JsonPayload.json(response);
}
throw Exceptions.forbidden("forbidden to delete [%s] objects", type);
}
示例3: deleteGetLogRequestsFromLogs
import org.elasticsearch.action.deletebyquery.DeleteByQueryResponse; //导入依赖的package包/类
private void deleteGetLogRequestsFromLogs() {
Utils.info("[SpaceDog] Deleting [GET] [/1/log] requests from logs ...");
BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery()//
.filter(QueryBuilders.termQuery("method", "GET"))//
.filter(QueryBuilders.termQuery("path", "/1/log"));
String querySource = new QuerySourceBuilder()//
.setQuery(queryBuilder)//
.toString();
DeleteByQueryResponse response = get().getElasticClient()//
.deleteByQuery(querySource, Resource.SPACEDOG_BACKEND, LogResource.TYPE);
Utils.info("[SpaceDog] [%s] logs deleted", response.getTotalDeleted());
}
示例4: deletePingRequestsFromLogs
import org.elasticsearch.action.deletebyquery.DeleteByQueryResponse; //导入依赖的package包/类
private void deletePingRequestsFromLogs() {
Utils.info("[SpaceDog] Deleting [GET] [/] requests from logs ...");
BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery()//
.filter(QueryBuilders.termQuery("method", "GET"))//
.filter(QueryBuilders.termQuery("path", "/"));
String querySource = new QuerySourceBuilder()//
.setQuery(queryBuilder)//
.toString();
DeleteByQueryResponse response = get().getElasticClient()//
.deleteByQuery(querySource, Resource.SPACEDOG_BACKEND, LogResource.TYPE);
Utils.info("[SpaceDog] [%s] logs deleted", response.getTotalDeleted());
}
示例5: doPurgeBackend
import org.elasticsearch.action.deletebyquery.DeleteByQueryResponse; //导入依赖的package包/类
private Optional<DeleteByQueryResponse> doPurgeBackend(DateTime before, //
Optional<String> optBackendId) {
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery()//
.filter(QueryBuilders.rangeQuery(FIELD_RECEIVED_AT).lt(before.toString()));
if (optBackendId.isPresent())
boolQueryBuilder.filter(//
QueryBuilders.termQuery("credentials.backendId", optBackendId.get()));
String query = new QuerySourceBuilder().setQuery(boolQueryBuilder).toString();
DeleteByQueryResponse delete = Start.get().getElasticClient()//
.deleteByQuery(query, SPACEDOG_BACKEND, TYPE);
// TODO why return an optional?
// return directly the response
return Optional.of(delete);
}
示例6: json
import org.elasticsearch.action.deletebyquery.DeleteByQueryResponse; //导入依赖的package包/类
public static Payload json(DeleteByQueryResponse response) {
if (response.isTimedOut())
return error(504, //
"the delete by query operation timed out, some objects might have been deleted");
if (response.getTotalFound() != response.getTotalDeleted())
return error(500, String.format(//
"the delete by query operation failed to delete all objects found, "
+ "objects found [%s], objects deleted [%s]",
response.getTotalFound(), response.getTotalDeleted()));
if (response.getShardFailures().length > 0)
return json(500, response.getShardFailures());
return json(builder()//
.put("totalDeleted", response.getTotalDeleted()));
}
示例7: deleteAll
import org.elasticsearch.action.deletebyquery.DeleteByQueryResponse; //导入依赖的package包/类
protected GDSResult<Boolean> deleteAll(Class<?> clazz, List<String> ids) {
final GDSAsyncImpl<Boolean> callback = new GDSAsyncImpl<>();
String kind = GDSClass.getKind(clazz);
String[] idArr = ids.toArray(new String[ids.size()]);
gds.getClient().prepareDeleteByQuery(gds.indexFor(kind))
.setQuery(QueryBuilders.idsQuery(kind).ids(idArr)).execute(new ActionListener<DeleteByQueryResponse>() {
@Override
public void onResponse(DeleteByQueryResponse response) {
callback.onSuccess(true, null);
}
@Override
public void onFailure(Throwable e) {
callback.onSuccess(false, e);
}
});
return callback;
}
示例8: deleteIndexByQuery
import org.elasticsearch.action.deletebyquery.DeleteByQueryResponse; //导入依赖的package包/类
/**
* Delete index by query.
*
* @param uid
* the uid
*/
private void deleteIndexByQuery(String uid) {
try {
/** Don't handle plugin deployment documents, skip them */
if(!uid.endsWith(ElasticsearchIndexerConstants.WAR)){
Client client = _esConnector.getClient();
DeleteByQueryResponse response = client
.prepareDeleteByQuery(ElasticsearchIndexerConstants.ELASTIC_SEARCH_LIFERAY_INDEX)
.setQuery(QueryBuilders.queryString(ElasticsearchIndexerConstants.ELASTIC_SEARCH_QUERY_UID + uid))
.execute().actionGet();
if (_log.isDebugEnabled()) {
_log.debug("Document deleted successfully with Id:" + uid + " , Status:" + response.status());
}
}
} catch (NoNodeAvailableException noNodeEx) {
_log.error("No node available:" + noNodeEx.getDetailedMessage());
} catch (IndexMissingException indexMissingEx) {
_log.error("No index availabe:" + indexMissingEx.getDetailedMessage());
}
}
开发者ID:rivetlogic,项目名称:liferay-elasticsearch-integration,代码行数:28,代码来源:ElasticsearchIndexWriterImpl.java
示例9: buildDelete
import org.elasticsearch.action.deletebyquery.DeleteByQueryResponse; //导入依赖的package包/类
public void buildDelete(XContentBuilder builder,
DeleteByQueryResponse response) throws IOException {
builder.startObject();
builder.startObject("_indices");
for (IndexDeleteByQueryResponse indexDeleteByQueryResponse : response
.getIndices().values()) {
builder.startObject(indexDeleteByQueryResponse.getIndex(),
XContentBuilder.FieldCaseConversion.NONE);
builder.startObject("_shards");
builder.field("total", indexDeleteByQueryResponse.getTotalShards());
builder.field("successful",
indexDeleteByQueryResponse.getSuccessfulShards());
builder.field("failed",
indexDeleteByQueryResponse.getFailedShards());
builder.endObject();
builder.endObject();
}
builder.endObject();
builder.endObject();
}
示例10: deleteOldFiles
import org.elasticsearch.action.deletebyquery.DeleteByQueryResponse; //导入依赖的package包/类
private void deleteOldFiles(String repo, List<String> projectsUpdated) {
String cutoffDate = DevSearchDateFormat.format(lastIndexDateForProjects);
LOG.info("deleting all previously indexed files for {}::{} with cutoff {}",repo, projectsUpdated, cutoffDate);
for (String projectName : projectsUpdated) {
// Not terribly efficient, but terms query has a size limit.
DeleteByQueryRequestBuilder deleteRequest = esClient.prepareDeleteByQuery(codeIndex)
.setTypes(DOC_TYPE)
.setQuery(QueryBuilders.boolQuery()
// .must(QueryBuilders.inQuery("project", projectsUpdated))
.must(QueryBuilders.termQuery("project", projectName))
.must(QueryBuilders.termQuery("repo", repo))
.mustNot(QueryBuilders.rangeQuery("lastIndexed").gte(cutoffDate)));
DeleteByQueryResponse response = deleteRequest.execute().actionGet();
checkForFailures(projectName, response);
}
LOG.info("done deleting all previously indexed files");
}
示例11: toXContent
import org.elasticsearch.action.deletebyquery.DeleteByQueryResponse; //导入依赖的package包/类
@Override
protected XContentBuilder toXContent(DeleteByQueryRequest request, DeleteByQueryResponse response, XContentBuilder builder) throws IOException {
builder.startObject().field(Fields.OK, true);
builder.startObject("_indices");
for (IndexDeleteByQueryResponse indexDeleteByQueryResponse : response.getIndices().values()) {
builder.startObject(indexDeleteByQueryResponse.getIndex(), XContentBuilder.FieldCaseConversion.NONE);
builder.startObject("_shards");
builder.field("total", indexDeleteByQueryResponse.getTotalShards());
builder.field("successful", indexDeleteByQueryResponse.getSuccessfulShards());
builder.field("failed", indexDeleteByQueryResponse.getFailedShards());
builder.endObject();
builder.endObject();
}
builder.endObject();
builder.endObject();
return builder;
}
示例12: clearIndex
import org.elasticsearch.action.deletebyquery.DeleteByQueryResponse; //导入依赖的package包/类
@Override
public Completable clearIndex(String indexName) {
return Completable.create(sub -> {
long start = System.currentTimeMillis();
if (log.isDebugEnabled()) {
log.debug("Clearing index {" + indexName + "}");
}
DeleteByQueryRequestBuilder builder = new DeleteByQueryRequestBuilder(getSearchClient(), DeleteByQueryAction.INSTANCE);
builder.setIndices(indexName).setQuery(QueryBuilders.matchAllQuery()).execute().addListener(new ActionListener<DeleteByQueryResponse>() {
public void onResponse(DeleteByQueryResponse response) {
if (log.isDebugEnabled()) {
log.debug("Clearing index {" + indexName + "}. Duration " + (System.currentTimeMillis() - start) + "[ms]");
}
sub.onComplete();
};
@Override
public void onFailure(Throwable e) {
if (e instanceof IndexNotFoundException) {
if (log.isDebugEnabled()) {
log.debug("Clearing index failed since the index does not exists. We ignore this error", e);
}
sub.onComplete();
} else {
log.error("Clearing index {" + indexName + "} failed. Duration " + (System.currentTimeMillis() - start) + "[ms]", e);
sub.onError(e);
}
}
});
});
}
示例13: buildResponse
import org.elasticsearch.action.deletebyquery.DeleteByQueryResponse; //导入依赖的package包/类
@Override
public RestResponse buildResponse(DeleteByQueryResponse result, XContentBuilder builder) throws Exception {
RestStatus restStatus = result.status();
builder.startObject();
builder.startObject(Fields._INDICES);
for (IndexDeleteByQueryResponse indexDeleteByQueryResponse : result.getIndices().values()) {
builder.startObject(indexDeleteByQueryResponse.getIndex(), XContentBuilder.FieldCaseConversion.NONE);
builder.startObject(Fields._SHARDS);
builder.field(Fields.TOTAL, indexDeleteByQueryResponse.getTotalShards());
builder.field(Fields.SUCCESSFUL, indexDeleteByQueryResponse.getSuccessfulShards());
builder.field(Fields.FAILED, indexDeleteByQueryResponse.getFailedShards());
ShardOperationFailedException[] failures = indexDeleteByQueryResponse.getFailures();
if (failures != null && failures.length > 0) {
builder.startArray(Fields.FAILURES);
for (ShardOperationFailedException shardFailure : failures) {
builder.startObject();
builder.field(Fields.INDEX, shardFailure.index());
builder.field(Fields.SHARD, shardFailure.shardId());
builder.field(Fields.REASON, shardFailure.reason());
builder.endObject();
}
builder.endArray();
}
builder.endObject();
builder.endObject();
}
builder.endObject();
builder.endObject();
return new BytesRestResponse(restStatus, builder);
}
示例14: deleteAll
import org.elasticsearch.action.deletebyquery.DeleteByQueryResponse; //导入依赖的package包/类
DeleteByQueryResponse deleteAll(String backendId) {
ElasticClient elastic = Start.get().getElasticClient();
// need to refresh index before and after delete
elastic.refreshType(SPACEDOG_BACKEND, TYPE);
DeleteByQueryResponse response = elastic.deleteByQuery(SPACEDOG_BACKEND,
QueryBuilders.termQuery(FIELD_BACKEND_ID, backendId), TYPE);
elastic.refreshType(SPACEDOG_BACKEND, TYPE);
return response;
}
示例15: deleteAllTypes
import org.elasticsearch.action.deletebyquery.DeleteByQueryResponse; //导入依赖的package包/类
@Delete("")
@Delete("/")
public Payload deleteAllTypes(String query, Context context) {
// TODO delete special types like user the right way
// credentials and user data at the same time
Credentials credentials = SpaceContext.checkAdminCredentials();
String[] types = DataAccessControl.types(DataPermission.delete_all, credentials);
boolean refresh = context.query().getBoolean(PARAM_REFRESH, true);
DataStore.get().refreshBackend(refresh, credentials.backendId());
DeleteByQueryResponse response = Start.get().getElasticClient()//
.deleteByQuery(query, credentials.backendId(), types);
return JsonPayload.json(response);
}