當前位置: 首頁>>代碼示例>>Java>>正文


Java DeleteRequest類代碼示例

本文整理匯總了Java中org.elasticsearch.action.delete.DeleteRequest的典型用法代碼示例。如果您正苦於以下問題:Java DeleteRequest類的具體用法?Java DeleteRequest怎麽用?Java DeleteRequest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DeleteRequest類屬於org.elasticsearch.action.delete包,在下文中一共展示了DeleteRequest類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: delete

import org.elasticsearch.action.delete.DeleteRequest; //導入依賴的package包/類
static Request delete(DeleteRequest deleteRequest) {
    String endpoint = endpoint(deleteRequest.index(), deleteRequest.type(), deleteRequest.id());

    Params parameters = Params.builder();
    parameters.withRouting(deleteRequest.routing());
    parameters.withParent(deleteRequest.parent());
    parameters.withTimeout(deleteRequest.timeout());
    parameters.withVersion(deleteRequest.version());
    parameters.withVersionType(deleteRequest.versionType());
    parameters.withRefreshPolicy(deleteRequest.getRefreshPolicy());
    parameters.withWaitForActiveShards(deleteRequest.waitForActiveShards());

    return new Request(HttpDelete.METHOD_NAME, endpoint, parameters.getParams(), null);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:15,代碼來源:Request.java

示例2: prepareRequest

import org.elasticsearch.action.delete.DeleteRequest; //導入依賴的package包/類
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    DeleteRequest deleteRequest = new DeleteRequest(request.param("index"), request.param("type"), request.param("id"));
    deleteRequest.routing(request.param("routing"));
    deleteRequest.parent(request.param("parent"));
    deleteRequest.timeout(request.paramAsTime("timeout", DeleteRequest.DEFAULT_TIMEOUT));
    deleteRequest.setRefreshPolicy(request.param("refresh"));
    deleteRequest.version(RestActions.parseVersion(request));
    deleteRequest.versionType(VersionType.fromString(request.param("version_type"), deleteRequest.versionType()));

    String waitForActiveShards = request.param("wait_for_active_shards");
    if (waitForActiveShards != null) {
        deleteRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards));
    }

    return channel -> client.delete(deleteRequest, new RestStatusToXContentListener<>(channel));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:18,代碼來源:RestDeleteAction.java

示例3: scriptChangedOpType

import org.elasticsearch.action.delete.DeleteRequest; //導入依賴的package包/類
protected RequestWrapper<?> scriptChangedOpType(RequestWrapper<?> request, OpType oldOpType, OpType newOpType) {
    switch (newOpType) {
    case NOOP:
        task.countNoop();
        return null;
    case DELETE:
        RequestWrapper<DeleteRequest> delete = wrap(new DeleteRequest(request.getIndex(), request.getType(), request.getId()));
        delete.setVersion(request.getVersion());
        delete.setVersionType(VersionType.INTERNAL);
        delete.setParent(request.getParent());
        delete.setRouting(request.getRouting());
        return delete;
    default:
        throw new IllegalArgumentException("Unsupported operation type change from [" + oldOpType + "] to [" + newOpType + "]");
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:17,代碼來源:AbstractAsyncBulkByScrollAction.java

示例4: testBulkRequestWithRefresh

import org.elasticsearch.action.delete.DeleteRequest; //導入依賴的package包/類
public void testBulkRequestWithRefresh() throws Exception {
    BulkRequest bulkRequest = new BulkRequest();
    // We force here a "id is missing" validation error
    bulkRequest.add(new DeleteRequest("index", "type", null).setRefreshPolicy(RefreshPolicy.IMMEDIATE));
    // We force here a "type is missing" validation error
    bulkRequest.add(new DeleteRequest("index", null, "id"));
    bulkRequest.add(new DeleteRequest("index", "type", "id").setRefreshPolicy(RefreshPolicy.IMMEDIATE));
    bulkRequest.add(new UpdateRequest("index", "type", "id").doc("{}", XContentType.JSON).setRefreshPolicy(RefreshPolicy.IMMEDIATE));
    bulkRequest.add(new IndexRequest("index", "type", "id").source("{}", XContentType.JSON).setRefreshPolicy(RefreshPolicy.IMMEDIATE));
    ActionRequestValidationException validate = bulkRequest.validate();
    assertThat(validate, notNullValue());
    assertThat(validate.validationErrors(), not(empty()));
    assertThat(validate.validationErrors(), contains(
            "RefreshPolicy is not supported on an item request. Set it on the BulkRequest instead.",
            "id is missing",
            "type is missing",
            "RefreshPolicy is not supported on an item request. Set it on the BulkRequest instead.",
            "RefreshPolicy is not supported on an item request. Set it on the BulkRequest instead.",
            "RefreshPolicy is not supported on an item request. Set it on the BulkRequest instead."));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:21,代碼來源:BulkRequestTests.java

示例5: testThatMissingIndexDoesNotAbortFullBulkRequest

import org.elasticsearch.action.delete.DeleteRequest; //導入依賴的package包/類
public void testThatMissingIndexDoesNotAbortFullBulkRequest() throws Exception{
    createIndex("bulkindex1", "bulkindex2");
    BulkRequest bulkRequest = new BulkRequest();
    bulkRequest.add(new IndexRequest("bulkindex1", "index1_type", "1").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo1"))
               .add(new IndexRequest("bulkindex2", "index2_type", "1").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo2"))
               .add(new IndexRequest("bulkindex2", "index2_type").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo2"))
               .add(new UpdateRequest("bulkindex2", "index2_type", "2").doc(Requests.INDEX_CONTENT_TYPE, "foo", "bar"))
               .add(new DeleteRequest("bulkindex2", "index2_type", "3"))
               .setRefreshPolicy(RefreshPolicy.IMMEDIATE);

    client().bulk(bulkRequest).get();
    SearchResponse searchResponse = client().prepareSearch("bulkindex*").get();
    assertHitCount(searchResponse, 3);

    assertAcked(client().admin().indices().prepareClose("bulkindex2"));

    BulkResponse bulkResponse = client().bulk(bulkRequest).get();
    assertThat(bulkResponse.hasFailures(), is(true));
    assertThat(bulkResponse.getItems().length, is(5));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:21,代碼來源:BulkWithUpdatesIT.java

示例6: testFailedRequestsOnClosedIndex

import org.elasticsearch.action.delete.DeleteRequest; //導入依賴的package包/類
public void testFailedRequestsOnClosedIndex() throws Exception {
    createIndex("bulkindex1");

    client().prepareIndex("bulkindex1", "index1_type", "1").setSource("text", "test").get();
    assertAcked(client().admin().indices().prepareClose("bulkindex1"));

    BulkRequest bulkRequest = new BulkRequest().setRefreshPolicy(RefreshPolicy.IMMEDIATE);
    bulkRequest.add(new IndexRequest("bulkindex1", "index1_type", "1").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo1"))
            .add(new UpdateRequest("bulkindex1", "index1_type", "1").doc(Requests.INDEX_CONTENT_TYPE, "foo", "bar"))
            .add(new DeleteRequest("bulkindex1", "index1_type", "1"));

    BulkResponse bulkResponse = client().bulk(bulkRequest).get();
    assertThat(bulkResponse.hasFailures(), is(true));
    BulkItemResponse[] responseItems = bulkResponse.getItems();
    assertThat(responseItems.length, is(3));
    assertThat(responseItems[0].getOpType(), is(OpType.INDEX));
    assertThat(responseItems[1].getOpType(), is(OpType.UPDATE));
    assertThat(responseItems[2].getOpType(), is(OpType.DELETE));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:20,代碼來源:BulkWithUpdatesIT.java

示例7: bulkDelete

import org.elasticsearch.action.delete.DeleteRequest; //導入依賴的package包/類
public String bulkDelete(String index,String type,String... ids){
	try {
		if(xclient==null){
			init();
		}
		BulkRequest request = new BulkRequest();
		for (String id : ids) {
			request.add(new DeleteRequest(index, type, id));
		}
		BulkResponse result = xclient.bulk(request);
		return result.toString();
	}catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}
 
開發者ID:dev-share,項目名稱:css-elasticsearch,代碼行數:18,代碼來源:ElasticsearchHighRestFactory.java

示例8: getClassType

import org.elasticsearch.action.delete.DeleteRequest; //導入依賴的package包/類
public static <Request extends ActionRequest> short getClassType(final Request request) {
    if (DeleteRequest.class.isInstance(request)) {
        return RequestUtils.TYPE_DELETE;
    } else if (DeleteByQueryRequest.class.isInstance(request)) {
        return RequestUtils.TYPE_DELETE_BY_QUERY;
    } else if (IndexRequest.class.isInstance(request)) {
        return RequestUtils.TYPE_INDEX;
    } else if (UpdateRequest.class.isInstance(request)) {
        return RequestUtils.TYPE_UPDATE;
    } else if (UpdateByQueryRequest.class.isInstance(request)) {
        return RequestUtils.TYPE_UPDATE_BY_QUERY;
    } else if (BulkRequest.class.isInstance(request)) {
        return RequestUtils.TYPE_BULK;
    }
    return 0;
}
 
開發者ID:codelibs,項目名稱:elasticsearch-indexing-proxy,代碼行數:17,代碼來源:RequestUtils.java

示例9: newRequest

import org.elasticsearch.action.delete.DeleteRequest; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public static <Request extends ActionRequest> Request newRequest(final short classType) {
    switch (classType) {
    case RequestUtils.TYPE_DELETE:
        return (Request) new DeleteRequest();
    case RequestUtils.TYPE_DELETE_BY_QUERY:
        return (Request) new DeleteByQueryRequest();
    case RequestUtils.TYPE_INDEX:
        return (Request) new IndexRequest();
    case RequestUtils.TYPE_UPDATE:
        return (Request) new UpdateRequest();
    case RequestUtils.TYPE_UPDATE_BY_QUERY:
        return (Request) new UpdateByQueryRequest();
    case RequestUtils.TYPE_BULK:
        return (Request) new BulkRequest();
    default:
        throw new ElasticsearchException("Unknown request type: " + classType);
    }
}
 
開發者ID:codelibs,項目名稱:elasticsearch-indexing-proxy,代碼行數:20,代碼來源:RequestUtils.java

示例10: createBulkRequest

import org.elasticsearch.action.delete.DeleteRequest; //導入依賴的package包/類
public static BulkRequestBuilder createBulkRequest(final Client client, final StreamInput streamInput, final String index)
        throws IOException {
    final BulkRequestBuilder builder = client.prepareBulk();
    final BulkRequest request = builder.request();
    request.readFrom(streamInput);
    if (index != null) {
        request.requests().stream().forEach(req -> {
            if (req instanceof DeleteRequest) {
                ((DeleteRequest) req).index(index);
            } else if (req instanceof DeleteByQueryRequest) {
                ((DeleteByQueryRequest) req).indices(index);
            } else if (req instanceof IndexRequest) {
                ((IndexRequest) req).index(index);
            } else if (req instanceof UpdateRequest) {
                ((UpdateRequest) req).index(index);
            } else if (req instanceof UpdateByQueryRequest) {
                ((UpdateByQueryRequest) req).indices(index);
            } else {
                throw new ElasticsearchException("Unsupported request in bulk: " + req);
            }
        });
    }
    return builder;
}
 
開發者ID:codelibs,項目名稱:elasticsearch-indexing-proxy,代碼行數:25,代碼來源:RequestUtils.java

示例11: ESDeleteTask

import org.elasticsearch.action.delete.DeleteRequest; //導入依賴的package包/類
public ESDeleteTask(UUID jobId,
                    ESDeleteNode node,
                    TransportDeleteAction transport,
                    JobContextService jobContextService) {
    super(jobId, node.executionPhaseId(), node.docKeys().size(), jobContextService);
    List<DeleteRequest> requests = new ArrayList<>(node.docKeys().size());
    List<ActionListener> listeners = new ArrayList<>(node.docKeys().size());
    for (DocKeys.DocKey docKey : node.docKeys()) {
        DeleteRequest request = new DeleteRequest(
                ESGetTask.indexName(node.tableInfo(), docKey.partitionValues()),
                Constants.DEFAULT_MAPPING_TYPE, docKey.id());
        request.routing(docKey.routing());
        if (docKey.version().isPresent()) {
            request.version(docKey.version().get());
        }
        requests.add(request);
        SettableFuture<TaskResult> result = SettableFuture.create();
        results.add(result);
        listeners.add(new DeleteResponseListener(result));
    }

    createContext("delete", requests, listeners, transport, null);
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:24,代碼來源:ESDeleteTask.java

示例12: purgeShards

import org.elasticsearch.action.delete.DeleteRequest; //導入依賴的package包/類
private void purgeShards(List<IndexShard> shardsToPurge) {
    for (IndexShard shardToPurge : shardsToPurge) {
        Query query = shardToPurge.indexService().mapperService().smartNameFieldType(TTLFieldMapper.NAME).rangeQuery(null, System.currentTimeMillis(), false, true);
        Engine.Searcher searcher = shardToPurge.acquireSearcher("indices_ttl");
        try {
            logger.debug("[{}][{}] purging shard", shardToPurge.routingEntry().index(), shardToPurge.routingEntry().id());
            ExpiredDocsCollector expiredDocsCollector = new ExpiredDocsCollector();
            searcher.searcher().search(query, expiredDocsCollector);
            List<DocToPurge> docsToPurge = expiredDocsCollector.getDocsToPurge();

            BulkRequest bulkRequest = new BulkRequest();
            for (DocToPurge docToPurge : docsToPurge) {

                bulkRequest.add(new DeleteRequest().index(shardToPurge.routingEntry().index()).type(docToPurge.type).id(docToPurge.id).version(docToPurge.version).routing(docToPurge.routing));
                bulkRequest = processBulkIfNeeded(bulkRequest, false);
            }
            processBulkIfNeeded(bulkRequest, true);
        } catch (Exception e) {
            logger.warn("failed to purge", e);
        } finally {
            searcher.close();
        }
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:25,代碼來源:IndicesTTLService.java

示例13: writeTo

import org.elasticsearch.action.delete.DeleteRequest; //導入依賴的package包/類
@Override
public void writeTo(StreamOutput out) throws IOException {
    super.writeTo(out);
    out.writeByte(consistencyLevel.id());
    out.writeVInt(requests.size());
    for (ActionRequest request : requests) {
        if (request instanceof IndexRequest) {
            out.writeByte((byte) 0);
        } else if (request instanceof DeleteRequest) {
            out.writeByte((byte) 1);
        } else if (request instanceof UpdateRequest) {
            out.writeByte((byte) 2);
        }
        request.writeTo(out);
    }
    out.writeBoolean(refresh);
    timeout.writeTo(out);
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:19,代碼來源:BulkRequest.java

示例14: setResponseFailureIfIndexMatches

import org.elasticsearch.action.delete.DeleteRequest; //導入依賴的package包/類
private boolean setResponseFailureIfIndexMatches(AtomicArray<BulkItemResponse> responses, int idx, ActionRequest request, String index, Throwable e) {
    if (request instanceof IndexRequest) {
        IndexRequest indexRequest = (IndexRequest) request;
        if (index.equals(indexRequest.index())) {
            responses.set(idx, new BulkItemResponse(idx, "index", new BulkItemResponse.Failure(indexRequest.index(), indexRequest.type(), indexRequest.id(), e)));
            return true;
        }
    } else if (request instanceof DeleteRequest) {
        DeleteRequest deleteRequest = (DeleteRequest) request;
        if (index.equals(deleteRequest.index())) {
            responses.set(idx, new BulkItemResponse(idx, "delete", new BulkItemResponse.Failure(deleteRequest.index(), deleteRequest.type(), deleteRequest.id(), e)));
            return true;
        }
    } else if (request instanceof UpdateRequest) {
        UpdateRequest updateRequest = (UpdateRequest) request;
        if (index.equals(updateRequest.index())) {
            responses.set(idx, new BulkItemResponse(idx, "update", new BulkItemResponse.Failure(updateRequest.index(), updateRequest.type(), updateRequest.id(), e)));
            return true;
        }
    } else {
        throw new ElasticsearchException("Parsed unknown request in bulk actions: " + request.getClass().getSimpleName());
    }
    return false;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:25,代碼來源:TransportBulkAction.java

示例15: deleteAllByQuery

import org.elasticsearch.action.delete.DeleteRequest; //導入依賴的package包/類
public void deleteAllByQuery(String index, String type, QueryBuilder query) {
  createBulkProcessor();
  SearchResponse scrollResp = getClient().prepareSearch(index).setSearchType(SearchType.QUERY_AND_FETCH).setTypes(type).setScroll(new TimeValue(60000)).setQuery(query).setSize(10000).execute()
      .actionGet();

  while (true) {
    for (SearchHit hit : scrollResp.getHits().getHits()) {
      DeleteRequest deleteRequest = new DeleteRequest(index, type, hit.getId());
      getBulkProcessor().add(deleteRequest);
    }

    scrollResp = getClient().prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(600000)).execute().actionGet();
    if (scrollResp.getHits().getHits().length == 0) {
      break;
    }

  }
  destroyBulkProcessor();
}
 
開發者ID:apache,項目名稱:incubator-sdap-mudrod,代碼行數:20,代碼來源:ESDriver.java


注:本文中的org.elasticsearch.action.delete.DeleteRequest類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。