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


Java UpdateRequest類代碼示例

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


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

示例1: index

import org.elasticsearch.action.update.UpdateRequest; //導入依賴的package包/類
@Override
public void index(Workflow workflow) {
	try {

		String id = workflow.getWorkflowId();
		WorkflowSummary summary = new WorkflowSummary(workflow);
		byte[] doc = om.writeValueAsBytes(summary);
		
		UpdateRequest req = new UpdateRequest(indexName, WORKFLOW_DOC_TYPE, id);
		req.doc(doc, XContentType.JSON);
		req.upsert(doc, XContentType.JSON);
		req.retryOnConflict(5);
		updateWithRetry(req);
			
	} catch (Throwable e) {
		log.error("Indexing failed {}", e.getMessage(), e);
	}
}
 
開發者ID:Netflix,項目名稱:conductor,代碼行數:19,代碼來源:ElasticSearchDAO.java

示例2: createUpdateRequest

import org.elasticsearch.action.update.UpdateRequest; //導入依賴的package包/類
private static UpdateRequest createUpdateRequest(Object document, Exchange exchange) {
    UpdateRequest updateRequest = new UpdateRequest();
    if (document instanceof byte[]) {
        updateRequest.doc((byte[]) document);
    } else if (document instanceof Map) {
        updateRequest.doc((Map<String, Object>) document);
    } else if (document instanceof String) {
        updateRequest.doc((String) document);
    } else if (document instanceof XContentBuilder) {
        updateRequest.doc((XContentBuilder) document);
    } else {
        return null;
    }

    return updateRequest
            .consistencyLevel(exchange.getIn().getHeader(
                    ElasticsearchConstants.PARAM_CONSISTENCY_LEVEL, WriteConsistencyLevel.class))
            .parent(exchange.getIn().getHeader(
                    ElasticsearchConstants.PARENT, String.class))
            .index(exchange.getIn().getHeader(
                    ElasticsearchConstants.PARAM_INDEX_NAME, String.class))
            .type(exchange.getIn().getHeader(
                    ElasticsearchConstants.PARAM_INDEX_TYPE, String.class))
            .id(exchange.getIn().getHeader(
                    ElasticsearchConstants.PARAM_INDEX_ID, String.class));
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:27,代碼來源:ElasticsearchActionRequestConverter.java

示例3: should_use_doc_as_upsert

import org.elasticsearch.action.update.UpdateRequest; //導入依賴的package包/類
@Test
public void should_use_doc_as_upsert() throws Exception {
    BytesReference source = source().bytes();
    Map<String, Object> expected = SourceLookup.sourceAsMap(source);

    UpdateRequest updateRequest = new UpdateRequest(THE_INDEX, THE_TYPE, THE_ID).doc(source.toBytes());
    updateRequest.docAsUpsert(true);
    UpdateResponse updateResponse = httpClient.update(updateRequest).get();

    Assertions.assertThat(updateResponse.getIndex()).isEqualTo(THE_INDEX);
    Assertions.assertThat(updateResponse.getType()).isEqualTo(THE_TYPE);
    Assertions.assertThat(updateResponse.getId()).isEqualTo(THE_ID);
    Assertions.assertThat(updateResponse.getVersion()).isEqualTo(1);
    Assertions.assertThat(updateResponse.isCreated()).isTrue();

    Map<String, Object> actualSource = get(THE_INDEX, THE_TYPE, THE_ID).getSource();
    compareMap(expected, actualSource);
}
 
開發者ID:obourgain,項目名稱:elasticsearch-http,代碼行數:19,代碼來源:UpdateActionHandlerTest.java

示例4: should_marshall_update_request_with_upsert

import org.elasticsearch.action.update.UpdateRequest; //導入依賴的package包/類
@Test
public void should_marshall_update_request_with_upsert() throws Exception {
    UpdateRequest request = new UpdateRequest();
    request.index("the_index");
    request.type("the_type");
    request.id("the_id");
    request.upsert("bar", "baz");
    Observable<byte[]> observable = BulkActionMarshaller.lazyConvertToBytes(Collections.<ActionRequest>singletonList(request));
    assertHasSize(observable, 4);

    byte[] bytes = takeNth(observable, 0);
    assertThat(new String(bytes)).isEqualTo("{\"update\":{\"_index\":\"the_index\",\"_type\":\"the_type\",\"_id\":\"the_id\",\"_retry_on_conflict\":0}}");

    bytes = takeNth(observable, 1);
    assertThat(new String(bytes)).isEqualTo("\n");

    bytes = takeNth(observable, 2);
    assertThat(new String(bytes)).isEqualTo("{\"upsert\":{\"bar\":\"baz\"}}");

    bytes = takeNth(observable, 3);
    assertThat(new String(bytes)).isEqualTo("\n");
}
 
開發者ID:obourgain,項目名稱:elasticsearch-http,代碼行數:23,代碼來源:BulkActionMarshallerTest.java

示例5: internalAdd

import org.elasticsearch.action.update.UpdateRequest; //導入依賴的package包/類
BulkRequest internalAdd(UpdateRequest request, @Nullable Object payload) {
    Objects.requireNonNull(request, "'request' must not be null");
    requests.add(request);
    addPayload(payload);
    if (request.doc() != null) {
        sizeInBytes += request.doc().source().length();
    }
    if (request.upsertRequest() != null) {
        sizeInBytes += request.upsertRequest().source().length();
    }
    if (request.script() != null) {
        sizeInBytes += request.script().getIdOrCode().length() * 2;
    }
    indices.add(request.index());
    return this;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:17,代碼來源:BulkRequest.java

示例6: testSimpleBulk4

import org.elasticsearch.action.update.UpdateRequest; //導入依賴的package包/類
public void testSimpleBulk4() throws Exception {
    String bulkAction = copyToStringFromClasspath("/org/elasticsearch/action/bulk/simple-bulk4.json");
    BulkRequest bulkRequest = new BulkRequest();
    bulkRequest.add(bulkAction.getBytes(StandardCharsets.UTF_8), 0, bulkAction.length(), null, null, XContentType.JSON);
    assertThat(bulkRequest.numberOfActions(), equalTo(4));
    assertThat(((UpdateRequest) bulkRequest.requests().get(0)).id(), equalTo("1"));
    assertThat(((UpdateRequest) bulkRequest.requests().get(0)).retryOnConflict(), equalTo(2));
    assertThat(((UpdateRequest) bulkRequest.requests().get(0)).doc().source().utf8ToString(), equalTo("{\"field\":\"value\"}"));
    assertThat(((UpdateRequest) bulkRequest.requests().get(1)).id(), equalTo("0"));
    assertThat(((UpdateRequest) bulkRequest.requests().get(1)).type(), equalTo("type1"));
    assertThat(((UpdateRequest) bulkRequest.requests().get(1)).index(), equalTo("index1"));
    Script script = ((UpdateRequest) bulkRequest.requests().get(1)).script();
    assertThat(script, notNullValue());
    assertThat(script.getIdOrCode(), equalTo("counter += param1"));
    assertThat(script.getLang(), equalTo("javascript"));
    Map<String, Object> scriptParams = script.getParams();
    assertThat(scriptParams, notNullValue());
    assertThat(scriptParams.size(), equalTo(1));
    assertThat(((Integer) scriptParams.get("param1")), equalTo(1));
    assertThat(((UpdateRequest) bulkRequest.requests().get(1)).upsertRequest().source().utf8ToString(), equalTo("{\"counter\":1}"));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:22,代碼來源:BulkRequestTests.java

示例7: testBulkRequestWithRefresh

import org.elasticsearch.action.update.UpdateRequest; //導入依賴的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

示例8: testThatMissingIndexDoesNotAbortFullBulkRequest

import org.elasticsearch.action.update.UpdateRequest; //導入依賴的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

示例9: testFailedRequestsOnClosedIndex

import org.elasticsearch.action.update.UpdateRequest; //導入依賴的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

示例10: upsert

import org.elasticsearch.action.update.UpdateRequest; //導入依賴的package包/類
public String upsert(String index,String type,String id,Object json){
		try {
			if(xclient==null){
				init();
			}
//			IndexRequest indexRequest = new IndexRequest(index, type, id).source(json,XContentType.JSON);
//			UpdateRequest updateRequest = new UpdateRequest(index, type, id).doc(json,XContentType.JSON).upsert(indexRequest);
			UpdateRequest request = new UpdateRequest(index, type, id);
			request.upsert(JSON.parseObject(JSON.toJSONString(json)),XContentType.JSON);
			UpdateResponse response = xclient.update(request);
			return response.toString();
		}catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
 
開發者ID:dev-share,項目名稱:css-elasticsearch,代碼行數:18,代碼來源:ElasticsearchHighRestFactory.java

示例11: getClassType

import org.elasticsearch.action.update.UpdateRequest; //導入依賴的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

示例12: newRequest

import org.elasticsearch.action.update.UpdateRequest; //導入依賴的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

示例13: createBulkRequest

import org.elasticsearch.action.update.UpdateRequest; //導入依賴的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

示例14: writeTo

import org.elasticsearch.action.update.UpdateRequest; //導入依賴的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

示例15: setResponseFailureIfIndexMatches

import org.elasticsearch.action.update.UpdateRequest; //導入依賴的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


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