Java Code Examples for org.elasticsearch.action.update.UpdateResponse#getVersion()
The following examples show how to use
org.elasticsearch.action.update.UpdateResponse#getVersion() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransportClient.java From elasticsearch-jest-example with MIT License | 6 votes |
/** * 更新索引 * @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); }
Example 2
Source File: EsInstanceStore.java From soundwave with Apache License 2.0 | 5 votes |
@Override public long updateOrInsertInstance(EsInstance instance) throws Exception { UpdateResponse response = this.updateOrInsert(instance.getId(), updateMapper.writeValueAsBytes(instance), insertMapper.writeValueAsBytes(instance)); return response.isCreated() ? 0 : response.getVersion(); }
Example 3
Source File: EsInstanceStore.java From soundwave with Apache License 2.0 | 5 votes |
@Override public long update(EsInstance instance) throws Exception { UpdateResponse response = this.update(instance.getId(), updateMapper.writeValueAsBytes(instance), instance.getVersion()); return response.getVersion(); }
Example 4
Source File: EsServiceMappingStore.java From soundwave with Apache License 2.0 | 5 votes |
@Override public long updateOrInsertServiceMapping(EsServiceMapping serviceMapping) throws Exception { UpdateResponse response = this.updateOrInsert(serviceMapping.getName(), mapper.writeValueAsBytes(serviceMapping), mapper.writeValueAsBytes(serviceMapping)); return response.isCreated() ? 0 : response.getVersion(); }
Example 5
Source File: EsDailySnapshotStore.java From soundwave with Apache License 2.0 | 5 votes |
@Override public long updateOrInsert(EsDailySnapshotInstance instance) throws Exception { byte[] doc = essnapshotinstanceMapper.writeValueAsBytes(instance); UpdateResponse response = this.updateOrInsert(instance.getId(), doc, doc); return response.getVersion(); }
Example 6
Source File: EsDailySnapshotStore.java From soundwave with Apache License 2.0 | 5 votes |
@Override public long update(EsDailySnapshotInstance instance) throws Exception { byte[] doc = essnapshotinstanceMapper.writeValueAsBytes(instance); UpdateResponse response = this.update(instance.getId(), doc, instance.getVersion()); return response.getVersion(); }
Example 7
Source File: ElasticsearchIndex.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static long doUpdateRequest(ActionRequestBuilder<?, ? extends UpdateResponse, ?> request) throws IOException { UpdateResponse response = request.execute().actionGet(); boolean isUpsert = response.status().equals(RestStatus.CREATED); if (isUpsert) { throw new IOException("Unexpected upsert: " + request.get().getClass().getName()); } return response.getVersion(); }
Example 8
Source File: CaseController.java From skywalking with Apache License 2.0 | 5 votes |
private void update(String indexName) throws IOException { UpdateRequest request = new UpdateRequest(indexName, "1"); Map<String, Object> parameters = singletonMap("title", "c++ programing."); Script inline = new Script(ScriptType.INLINE, "painless", "ctx._source.title = params.title", parameters); request.script(inline); UpdateResponse updateResponse = client.update(request, RequestOptions.DEFAULT); if (updateResponse.getVersion() != 2) { String message = "elasticsearch update data fail."; logger.error(message); throw new RuntimeException(message); } }
Example 9
Source File: RestHighLevelClientCase.java From skywalking with Apache License 2.0 | 5 votes |
private void update(RestHighLevelClient client, String indexName) throws IOException { UpdateRequest request = new UpdateRequest(indexName, "_doc", "1"); Map<String, Object> parameters = singletonMap("title", "c++ programing."); Script inline = new Script(ScriptType.INLINE, "painless", "ctx._source.title = params.title", parameters); request.script(inline); UpdateResponse updateResponse = client.update(request, RequestOptions.DEFAULT); if (updateResponse.getVersion() != 2) { String message = "elasticsearch update data fail."; logger.error(message); throw new RuntimeException(message); } }
Example 10
Source File: TransportClient.java From elasticsearch-jest-example with MIT License | 5 votes |
/** * * @param index * @param type * @param id * @throws Exception */ private static void upsertIndex(String index,String type,String id) throws Exception{ Client client = createTransportClient(); IndexRequest indexRequest = new IndexRequest(index, type, id) .source(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()); UpdateRequest updateRequest = new UpdateRequest(index, type, id) .doc(jsonBuilder() .startObject() .field("author", "华东师范大学数据科学与工程学院") .endObject()) .upsert(indexRequest); UpdateResponse response = client.update(updateRequest).get(); 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); }
Example 11
Source File: TransportClient.java From elasticsearch-jest-example with MIT License | 5 votes |
/** * 更新索引 https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html * @param index * @param type * @param id */ private static void updateIndexByScript(String index, String type, String id) throws Exception{ Client client = createTransportClient(); UpdateResponse response = client.prepareUpdate(index, type, id) .setScript("ctx._source.author = \"闫洪磊\";" + "ctx._source.name = \"Activiti实战\";" + "ctx._source.pubinfo = \"机械工业出版社\";" + "ctx._source.pubtime = \"2015-01-01\";" + "ctx._source.desc = \"《Activiti实战 》立足于实践,不仅让读者知其然,全面掌握Activiti架构、功能、用法、技巧和最佳实践,广度足够;而且让读者知其所以然,深入理解Activiti的源代码实现、设计模式和PVM,深度也足够。《Activiti实战 》一共四个部分:准备篇(1~2章)介绍了Activiti的概念、特点、应用、体系结构,以及开发环境的搭建和配置;基础篇(3~4章)首先讲解了Activiti Modeler、Activiti Designer两种流程设计工具的详细使用,然后详细讲解了BPMN2.0规范;实战篇(5~14章)系统讲解了Activiti的用法、技巧和最佳实践,包含流程定义、流程实例、任务、子流程、多实例、事件以及监听器等;高级篇(15~21)通过集成WebService、规则引擎、JPA、ESB等各种服务和中间件来阐述了Activiti不仅仅是引擎,实际上是一个BPM平台,最后还通过源代码对它的设计模式及PVM进行了分析。\"", ScriptService.ScriptType.INLINE) // .setScript("ctx._source.author = \"闫洪磊\"", ScriptService.ScriptType.INLINE) // .setScript("ctx._source.name = \"Activiti实战\"", ScriptService.ScriptType.INLINE) // .setScript("ctx._source.pubinfo = \"机械工业出版社\"", ScriptService.ScriptType.INLINE) // .setScript("ctx._source.pubtime = \"2015-01-01\"", ScriptService.ScriptType.INLINE) // .setScript("ctx._source.desc = \"《Activiti实战 》立足于实践,不仅让读者知其然,全面掌握Activiti架构、功能、用法、技巧和最佳实践,广度足够;而且让读者知其所以然,深入理解Activiti的源代码实现、设计模式和PVM,深度也足够。《Activiti实战 》一共四个部分:准备篇(1~2章)介绍了Activiti的概念、特点、应用、体系结构,以及开发环境的搭建和配置;基础篇(3~4章)首先讲解了Activiti Modeler、Activiti Designer两种流程设计工具的详细使用,然后详细讲解了BPMN2.0规范;实战篇(5~14章)系统讲解了Activiti的用法、技巧和最佳实践,包含流程定义、流程实例、任务、子流程、多实例、事件以及监听器等;高级篇(15~21)通过集成WebService、规则引擎、JPA、ESB等各种服务和中间件来阐述了Activiti不仅仅是引擎,实际上是一个BPM平台,最后还通过源代码对它的设计模式及PVM进行了分析。\"", ScriptService.ScriptType.INLINE) .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); }