當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。