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


Java UpdateRequest.upsert方法代码示例

本文整理汇总了Java中org.elasticsearch.action.update.UpdateRequest.upsert方法的典型用法代码示例。如果您正苦于以下问题:Java UpdateRequest.upsert方法的具体用法?Java UpdateRequest.upsert怎么用?Java UpdateRequest.upsert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.action.update.UpdateRequest的用法示例。


在下文中一共展示了UpdateRequest.upsert方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: 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

示例4: add

import org.elasticsearch.action.update.UpdateRequest; //导入方法依赖的package包/类
@Override
public void add(EventExecution ee) {

	try {

		byte[] doc = om.writeValueAsBytes(ee);
		String id = ee.getName() + "." + ee.getEvent() + "." + ee.getMessageId() + "." + ee.getId();
		UpdateRequest req = new UpdateRequest(logIndexName, EVENT_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,代码行数:20,代码来源:ElasticSearchDAO.java

示例5: 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);
		req.upsert(doc);
		req.retryOnConflict(5);
		updateWithRetry(req);
			
	} catch (Throwable e) {
		log.error("Indexing failed {}", e.getMessage(), e);
	}
}
 
开发者ID:Netflix,项目名称:conductor,代码行数:19,代码来源:ElasticSearchDAO.java

示例6: add

import org.elasticsearch.action.update.UpdateRequest; //导入方法依赖的package包/类
@Override
public void add(EventExecution ee) {

	try {

		byte[] doc = om.writeValueAsBytes(ee);
		String id = ee.getName() + "." + ee.getEvent() + "." + ee.getMessageId() + "." + ee.getId();
		UpdateRequest req = new UpdateRequest(logIndexName, EVENT_DOC_TYPE, id);
		req.doc(doc);
		req.upsert(doc);
		req.retryOnConflict(5);
		updateWithRetry(req);
			
	} catch (Throwable e) {
		log.error("Indexing failed {}", e.getMessage(), e);
	}

	
}
 
开发者ID:Netflix,项目名称:conductor,代码行数:20,代码来源:ElasticSearchDAO.java

示例7: updateTagConfig

import org.elasticsearch.action.update.UpdateRequest; //导入方法依赖的package包/类
/**
 * Update a given tag config document, or create it if it doesn't exist.
 *
 * @param tag the tag
 */
void updateTagConfig(final TagConfigDocument tag) {
  if (!Indices.exists(configIndex)) {
    Indices.create(configIndex, TYPE, MappingFactory.createTagConfigMapping());
  }

  UpdateRequest updateRequest = new UpdateRequest(configIndex, TYPE,
        String.valueOf(tag.getId())).doc(tag.toString()).routing(tag.getId());
    updateRequest.upsert(this.getIndexRequest(tag));
    try {
      client.getClient().update(updateRequest).get();
      client.waitForYellowStatus();
    } catch (Exception e) {
      log.error("Error occurred while updating the config for tag #{}", tag.getId(), e);
  }
}
 
开发者ID:c2mon,项目名称:c2mon,代码行数:21,代码来源:TagConfigDocumentIndexer.java

示例8: should_marshall_update_request_with_script_and_upsert

import org.elasticsearch.action.update.UpdateRequest; //导入方法依赖的package包/类
@Test
public void should_marshall_update_request_with_script_and_upsert() throws Exception {
    UpdateRequest request = new UpdateRequest();
    request.index("the_index");
    request.type("the_type");
    request.id("the_id");
    request.script("the_script");
    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\"},\"script\":\"the_script\"}");

    bytes = takeNth(observable, 3);
    assertThat(new String(bytes)).isEqualTo("\n");
}
 
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:24,代码来源:BulkActionMarshallerTest.java


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