当前位置: 首页>>代码示例>>Java>>正文


Java UpdateResponse类代码示例

本文整理汇总了Java中org.elasticsearch.action.update.UpdateResponse的典型用法代码示例。如果您正苦于以下问题:Java UpdateResponse类的具体用法?Java UpdateResponse怎么用?Java UpdateResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


UpdateResponse类属于org.elasticsearch.action.update包,在下文中一共展示了UpdateResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testNoopUpdateReplicaRequest

import org.elasticsearch.action.update.UpdateResponse; //导入依赖的package包/类
public void testNoopUpdateReplicaRequest() throws Exception {
    DocWriteRequest writeRequest = new IndexRequest("index", "type", "id").source(Requests.INDEX_CONTENT_TYPE, "field", "value");
    BulkItemRequest replicaRequest = new BulkItemRequest(0, writeRequest);

    DocWriteResponse noopUpdateResponse = new UpdateResponse(shardId, "index", "id", 0, DocWriteResponse.Result.NOOP);
    BulkItemResultHolder noopResults = new BulkItemResultHolder(noopUpdateResponse, null, replicaRequest);

    Translog.Location location = new Translog.Location(0, 0, 0);
    BulkItemRequest[] items = new BulkItemRequest[0];
    BulkShardRequest bulkShardRequest = new BulkShardRequest(shardId, RefreshPolicy.NONE, items);
    Translog.Location newLocation = TransportShardBulkAction.updateReplicaRequest(noopResults,
            DocWriteRequest.OpType.UPDATE, location, bulkShardRequest);

    BulkItemResponse primaryResponse = replicaRequest.getPrimaryResponse();

    // Basically nothing changes in the request since it's a noop
    assertThat(newLocation, equalTo(location));
    assertThat(primaryResponse.getItemId(), equalTo(0));
    assertThat(primaryResponse.getId(), equalTo("id"));
    assertThat(primaryResponse.getOpType(), equalTo(DocWriteRequest.OpType.UPDATE));
    assertThat(primaryResponse.getResponse(), equalTo(noopUpdateResponse));
    assertThat(primaryResponse.getResponse().getResult(), equalTo(DocWriteResponse.Result.NOOP));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:TransportShardBulkActionTests.java

示例2: upsert

import org.elasticsearch.action.update.UpdateResponse; //导入依赖的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

示例3: writeTo

import org.elasticsearch.action.update.UpdateResponse; //导入依赖的package包/类
@Override
public void writeTo(StreamOutput out) throws IOException {
    out.writeVInt(id);
    out.writeString(opType);

    if (response == null) {
        out.writeByte((byte) 2);
    } else {
        if (response instanceof IndexResponse) {
            out.writeByte((byte) 0);
        } else if (response instanceof DeleteResponse) {
            out.writeByte((byte) 1);
        } else if (response instanceof UpdateResponse) {
            out.writeByte((byte) 3); // make 3 instead of 2, because 2 is already in use for 'no responses'
        }
        response.writeTo(out);
    }
    if (failure == null) {
        out.writeBoolean(false);
    } else {
        out.writeBoolean(true);
        failure.writeTo(out);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:25,代码来源:BulkItemResponse.java

示例4: update

import org.elasticsearch.action.update.UpdateResponse; //导入依赖的package包/类
@Override
public void update(String workflowInstanceId, String[] keys, Object[] values) {
	if(keys.length != values.length) {
		throw new IllegalArgumentException("Number of keys and values should be same.");
	}
	
	UpdateRequest request = new UpdateRequest(indexName, WORKFLOW_DOC_TYPE, workflowInstanceId);
	Map<String, Object> source = new HashMap<>();

	for (int i = 0; i < keys.length; i++) {
		String key = keys[i];
		Object value= values[i];
		log.debug("updating {} with {} and {}", workflowInstanceId, key, value);
		source.put(key, value);
	}
	request.doc(source);		
	ActionFuture<UpdateResponse> response = client.update(request);
	response.actionGet();
}
 
开发者ID:Netflix,项目名称:conductor,代码行数:20,代码来源:ElasticSearchDAO.java

示例5: addToIndex

import org.elasticsearch.action.update.UpdateResponse; //导入依赖的package包/类
/**
 * 文書をインデックスに追加する.
 * @param doc 文書
 * @return 結果
 */
public boolean addToIndex(ElasticsearchDocument doc) {
    ObjectMapper mapper = new ObjectMapper();
    String json;
    try {
        json = mapper.writeValueAsString(doc);
    } catch (JsonProcessingException e) {
        throw new ElasticsearchException("JSONへの変換に失敗しました", e);
    }

    String i = formatIndex(config.getIndex());
    IndexRequest createRequest = new IndexRequest(i, doc.type, doc.id).source(json);
    UpdateRequest updateRequest =
            new UpdateRequest(i, doc.type, doc.id).doc(json).upsert(createRequest);

    UpdateResponse response = client.update(updateRequest).actionGet();
    return response.isCreated();
}
 
开发者ID:otsecbsol,项目名称:linkbinder,代码行数:23,代码来源:ElasticsearchClient.java

示例6: updateIndexByDoc

import org.elasticsearch.action.update.UpdateResponse; //导入依赖的package包/类
/**
 * 更新索引
 * @param index
 * @param type
 * @param id
 */
private static void updateIndexByDoc(String index, String type, String id) throws Exception{
	Client client = createTransportClient();
	UpdateResponse response = client.prepareUpdate(index, type, id)
			.setDoc(jsonBuilder()
					.startObject()
					.field("name", "Hadoop权威指南(第3版 修订版)")
					.field("author", "Tom White")
					.field("pubinfo", "清华大学出版社")
					.field("pubtime", "2015-01-01")
					.field("desc", "《Hadoop权威指南(第3版 修订版)》通过丰富的案例学习来解释Hadoop的幕后机理,阐述了Hadoop如何解决现实生活中的具体问题。第3版覆盖Hadoop的最新动态,包括新增的MapReduceAPI,以及MapReduce2及其灵活性更强的执行模型(YARN)")
					.endObject())
			.execute()
			.actionGet();
	System.out.println("索引是否更新:"+response.isCreated());
	System.out.println("****************index ***********************");
	// Index name
	String _index = response.getIndex();
	// Type name
	String _type = response.getType();
	// Document ID (generated or not)
	String _id = response.getId();
	// Version (if it's the first time you index this document, you will get: 1)
	long _version = response.getVersion();
	System.out.println(_index + "," + _type + "," + _id + "," + _version);
}
 
开发者ID:ameizi,项目名称:elasticsearch-jest-example,代码行数:32,代码来源:TransportClient.java

示例7: toXContent

import org.elasticsearch.action.update.UpdateResponse; //导入依赖的package包/类
@Override
protected XContentBuilder toXContent(UpdateRequest request, UpdateResponse response, XContentBuilder builder) throws IOException {
    builder.startObject()
            .field(Fields.OK, true)
            .field(Fields._INDEX, response.getIndex())
            .field(Fields._TYPE, response.getType())
            .field(Fields._ID, response.getId())
            .field(Fields._VERSION, response.getVersion());

    if (response.getGetResult() != null) {
        builder.startObject(Fields.GET);
        response.getGetResult().toXContentEmbedded(builder, ToXContent.EMPTY_PARAMS);
        builder.endObject();
    }

    if (response.getMatches() != null) {
        builder.startArray(Fields.MATCHES);
        for (String match : response.getMatches()) {
            builder.value(match);
        }
        builder.endArray();
    }
    builder.endObject();
    return builder;
}
 
开发者ID:javanna,项目名称:elasticshell,代码行数:26,代码来源:UpdateRequestBuilder.java

示例8: update

import org.elasticsearch.action.update.UpdateResponse; //导入依赖的package包/类
private UpdateResponse update(Boolean detectNoop, long expectedVersion, XContentBuilder xContentBuilder) {
    UpdateRequestBuilder updateRequest = client().prepareUpdate("test", "type1", "1")
            .setDoc(xContentBuilder)
            .setDocAsUpsert(true)
            .setFields("_source");
    if (detectNoop != null) {
        updateRequest.setDetectNoop(detectNoop);
    }
    UpdateResponse updateResponse = updateRequest.get();
    assertThat(updateResponse.getGetResult(), notNullValue());
    assertEquals(expectedVersion, updateResponse.getVersion());
    return updateResponse;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:UpdateNoopIT.java

示例9: updateDocument

import org.elasticsearch.action.update.UpdateResponse; //导入依赖的package包/类
/**
 * This method updated the matched Document
 */
@Override
public void updateDocument() {
    try {
        client = ESclient.getInstant();
        UpdateRequest updateReguest = new UpdateRequest("school", "tenth", "1")
                .doc(jsonBuilder()
                        .startObject()
                        .field("name", "Sundar S")
                        .endObject());
        UpdateResponse updateResponse = client.update(updateReguest).get();
        if (updateResponse != null) {
            updateResponse.getGetResult();
            log.info("Index has been updated successfully...");
        }
    } catch (IOException | InterruptedException | ExecutionException ex) {
        log.error("Exception occurred while update Document : " + ex, ex);
    }
}
 
开发者ID:sundarcse1216,项目名称:es-crud,代码行数:22,代码来源:ElasticSearchCrudImpl.java

示例10: writeTo

import org.elasticsearch.action.update.UpdateResponse; //导入依赖的package包/类
@Override
public void writeTo(StreamOutput out) throws IOException {
    out.writeVInt(id);
    if (out.getVersion().onOrAfter(Version.V_5_3_0_UNRELEASED)) {
        out.writeByte(opType.getId());
    } else {
        out.writeString(opType.getLowercase());
    }

    if (response == null) {
        out.writeByte((byte) 2);
    } else {
        if (response instanceof IndexResponse) {
            out.writeByte((byte) 0);
        } else if (response instanceof DeleteResponse) {
            out.writeByte((byte) 1);
        } else if (response instanceof UpdateResponse) {
            out.writeByte((byte) 3); // make 3 instead of 2, because 2 is already in use for 'no responses'
        }
        response.writeTo(out);
    }
    if (failure == null) {
        out.writeBoolean(false);
    } else {
        out.writeBoolean(true);
        failure.writeTo(out);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:29,代码来源:BulkItemResponse.java

示例11: testUpsertDoc

import org.elasticsearch.action.update.UpdateResponse; //导入依赖的package包/类
public void testUpsertDoc() throws Exception {
    createTestIndex();
    ensureGreen();

    UpdateResponse updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1")
            .setDoc(XContentFactory.jsonBuilder().startObject().field("bar", "baz").endObject())
            .setDocAsUpsert(true)
            .setFields("_source")
            .execute().actionGet();
    assertThat(updateResponse.getIndex(), equalTo("test"));
    assertThat(updateResponse.getGetResult(), notNullValue());
    assertThat(updateResponse.getGetResult().getIndex(), equalTo("test"));
    assertThat(updateResponse.getGetResult().sourceAsMap().get("bar").toString(), equalTo("baz"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:UpdateIT.java

示例12: testUpsertFields

import org.elasticsearch.action.update.UpdateResponse; //导入依赖的package包/类
public void testUpsertFields() throws Exception {
    createTestIndex();
    ensureGreen();

    UpdateResponse updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1")
            .setUpsert(XContentFactory.jsonBuilder().startObject().field("bar", "baz").endObject())
            .setScript(new Script(ScriptType.INLINE, "put_values", "", Collections.singletonMap("extra", "foo")))
            .setFetchSource(true)
            .execute().actionGet();

    assertThat(updateResponse.getIndex(), equalTo("test"));
    assertThat(updateResponse.getGetResult(), notNullValue());
    assertThat(updateResponse.getGetResult().getIndex(), equalTo("test"));
    assertThat(updateResponse.getGetResult().sourceAsMap().get("bar").toString(), equalTo("baz"));
    assertThat(updateResponse.getGetResult().sourceAsMap().get("extra"), nullValue());

    updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1")
            .setUpsert(XContentFactory.jsonBuilder().startObject().field("bar", "baz").endObject())
            .setScript(new Script(ScriptType.INLINE, "put_values", "", Collections.singletonMap("extra", "foo")))
            .setFields("_source")
            .execute().actionGet();

    assertThat(updateResponse.getIndex(), equalTo("test"));
    assertThat(updateResponse.getGetResult(), notNullValue());
    assertThat(updateResponse.getGetResult().getIndex(), equalTo("test"));
    assertThat(updateResponse.getGetResult().sourceAsMap().get("bar").toString(), equalTo("baz"));
    assertThat(updateResponse.getGetResult().sourceAsMap().get("extra").toString(), equalTo("foo"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:29,代码来源:UpdateIT.java

示例13: testIndexAutoCreation

import org.elasticsearch.action.update.UpdateResponse; //导入依赖的package包/类
public void testIndexAutoCreation() throws Exception {
    UpdateResponse updateResponse = client().prepareUpdate("test", "type1", "1")
            .setUpsert(XContentFactory.jsonBuilder().startObject().field("bar", "baz").endObject())
            .setScript(new Script(ScriptType.INLINE, "put_values", "", Collections.singletonMap("extra", "foo")))
            .setFetchSource(true)
            .execute().actionGet();

    assertThat(updateResponse.getIndex(), equalTo("test"));
    assertThat(updateResponse.getGetResult(), notNullValue());
    assertThat(updateResponse.getGetResult().getIndex(), equalTo("test"));
    assertThat(updateResponse.getGetResult().sourceAsMap().get("bar").toString(), equalTo("baz"));
    assertThat(updateResponse.getGetResult().sourceAsMap().get("extra"), nullValue());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:UpdateIT.java

示例14: testUpdate

import org.elasticsearch.action.update.UpdateResponse; //导入依赖的package包/类
public void testUpdate() throws InterruptedException, ExecutionException {
    // Index normally
    indexRandom(true, client().prepareIndex("test", "test", "1").setSource("foo", "bar"));
    assertSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "bar")).get(), "1");

    // Update with RefreshPolicy.WAIT_UNTIL
    UpdateResponse update = client().prepareUpdate("test", "test", "1")
        .setDoc(Requests.INDEX_CONTENT_TYPE, "foo", "baz").setRefreshPolicy(RefreshPolicy.WAIT_UNTIL)
            .get();
    assertEquals(2, update.getVersion());
    assertFalse("request shouldn't have forced a refresh", update.forcedRefresh());
    assertSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "baz")).get(), "1");

    // Upsert with RefreshPolicy.WAIT_UNTIL
    update = client().prepareUpdate("test", "test", "2").setDocAsUpsert(true).setDoc(Requests.INDEX_CONTENT_TYPE, "foo", "cat")
            .setRefreshPolicy(RefreshPolicy.WAIT_UNTIL).get();
    assertEquals(1, update.getVersion());
    assertFalse("request shouldn't have forced a refresh", update.forcedRefresh());
    assertSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "cat")).get(), "2");

    // Update-becomes-delete with RefreshPolicy.WAIT_UNTIL
    update = client().prepareUpdate("test", "test", "2").setScript(new Script(ScriptType.INLINE, "native", "delete_plz", emptyMap()))
            .setRefreshPolicy(RefreshPolicy.WAIT_UNTIL).get();
    assertEquals(2, update.getVersion());
    assertFalse("request shouldn't have forced a refresh", update.forcedRefresh());
    assertNoSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "cat")).get());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:WaitUntilRefreshIT.java

示例15: testBulkUpdateMalformedScripts

import org.elasticsearch.action.update.UpdateResponse; //导入依赖的package包/类
public void testBulkUpdateMalformedScripts() throws Exception {
    createIndex("test");
    ensureGreen();

    BulkResponse bulkResponse = client().prepareBulk()
            .add(client().prepareIndex().setIndex("test").setType("type1").setId("1").setSource("field", 1))
            .add(client().prepareIndex().setIndex("test").setType("type1").setId("2").setSource("field", 1))
            .add(client().prepareIndex().setIndex("test").setType("type1").setId("3").setSource("field", 1))
            .execute().actionGet();

    assertThat(bulkResponse.hasFailures(), equalTo(false));
    assertThat(bulkResponse.getItems().length, equalTo(3));

    bulkResponse = client().prepareBulk()
            .add(client().prepareUpdate().setIndex("test").setType("type1").setId("1").setFields("field")
                    .setScript(new Script(
                        ScriptType.INLINE, CustomScriptPlugin.NAME, "throw script exception on unknown var", Collections.emptyMap())))
            .add(client().prepareUpdate().setIndex("test").setType("type1").setId("2").setFields("field")
                    .setScript(new Script(
                        ScriptType.INLINE, CustomScriptPlugin.NAME, "ctx._source.field += 1", Collections.emptyMap())))
            .add(client().prepareUpdate().setIndex("test").setType("type1").setId("3").setFields("field")
                    .setScript(new Script(
                        ScriptType.INLINE, CustomScriptPlugin.NAME, "throw script exception on unknown var", Collections.emptyMap())))
            .execute().actionGet();

    assertThat(bulkResponse.hasFailures(), equalTo(true));
    assertThat(bulkResponse.getItems().length, equalTo(3));
    assertThat(bulkResponse.getItems()[0].getFailure().getId(), equalTo("1"));
    assertThat(bulkResponse.getItems()[0].getFailure().getMessage(), containsString("failed to execute script"));
    assertThat(bulkResponse.getItems()[0].getResponse(), nullValue());

    assertThat(bulkResponse.getItems()[1].getResponse().getId(), equalTo("2"));
    assertThat(bulkResponse.getItems()[1].getResponse().getVersion(), equalTo(2L));
    assertThat(((UpdateResponse) bulkResponse.getItems()[1].getResponse()).getGetResult().field("field").getValue(), equalTo(2));
    assertThat(bulkResponse.getItems()[1].getFailure(), nullValue());

    assertThat(bulkResponse.getItems()[2].getFailure().getId(), equalTo("3"));
    assertThat(bulkResponse.getItems()[2].getFailure().getMessage(), containsString("failed to execute script"));
    assertThat(bulkResponse.getItems()[2].getResponse(), nullValue());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:41,代码来源:BulkWithUpdatesIT.java


注:本文中的org.elasticsearch.action.update.UpdateResponse类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。