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


Java UpdateRequest.doc方法代碼示例

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


在下文中一共展示了UpdateRequest.doc方法的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: 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

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

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

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

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

示例8: should_marshall_update_request

import org.elasticsearch.action.update.UpdateRequest; //導入方法依賴的package包/類
@Test
public void should_marshall_update_request() throws Exception {
    UpdateRequest request = new UpdateRequest();
    request.index("the_index");
    request.type("the_type");
    request.id("the_id");
    request.doc("foo", "bar");
    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("{\"doc\":{\"foo\":\"bar\"}}");
    bytes = takeNth(observable, 3);
    assertThat(new String(bytes)).isEqualTo("\n");
}
 
開發者ID:obourgain,項目名稱:elasticsearch-http,代碼行數:20,代碼來源:BulkActionMarshallerTest.java

示例9: should_marshall_update_request_with_doc_as_upsert

import org.elasticsearch.action.update.UpdateRequest; //導入方法依賴的package包/類
@Test
public void should_marshall_update_request_with_doc_as_upsert() throws Exception {
    UpdateRequest request = new UpdateRequest();
    request.index("the_index");
    request.type("the_type");
    request.id("the_id");
    request.doc("bar", "baz");
    request.docAsUpsert(true);
    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("{\"doc_as_upsert\":true,\"doc\":{\"bar\":\"baz\"}}");

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

示例10: convertDoc

import org.elasticsearch.action.update.UpdateRequest; //導入方法依賴的package包/類
@Override
protected ActionRequest convertDoc(Document document) {
  Document.Operation operation = document.getOperation();
  switch (operation) {
    case NEW: {
      IndexRequest indexRequest = new IndexRequest(getIndexName(), getObjectType(), document.getId());
      indexRequest.source(document.asMap());
      return indexRequest;
    }
    case UPDATE: {
      UpdateRequest updateRequest = new UpdateRequest(getIndexName(), getObjectType(), document.getId());
      updateRequest.doc(document.asMap());
      return updateRequest;
    }
    case DELETE: {
      return new DeleteRequest(getIndexName(), getObjectType(), document.getId());
    }
  }
  throw new UnsupportedOperationException("Operation was:" + operation);
}
 
開發者ID:nsoft,項目名稱:jesterj,代碼行數:21,代碼來源:ElasticSender.java

示例11: update

import org.elasticsearch.action.update.UpdateRequest; //導入方法依賴的package包/類
public String update(String index,String type,String id,Object json){
	try {
		if(xclient==null){
			init();
		}
		UpdateRequest request = new UpdateRequest(index, type, id);
		request.doc(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,代碼行數:16,代碼來源:ElasticsearchHighRestFactory.java

示例12: UpdateRequest

import org.elasticsearch.action.update.UpdateRequest; //導入方法依賴的package包/類
private static void UpdateRequest(Client client) throws IOException, InterruptedException, ExecutionException {

        //當更新的內容不存在的時候會添加  
        UpdateRequest updateRequest = new UpdateRequest();
        updateRequest.index("twitter");
        updateRequest.type("tweet");
        updateRequest.id("3");
        XContentBuilder jsonBuilder =XContentFactory.jsonBuilder();
        updateRequest.doc(jsonBuilder
                .startObject()
                .field("message","我是林誌穎啊")
                .field("user","lin")
                .endObject());
        UpdateResponse response= client.update(updateRequest).get();  
           
    /*   
     *  //當更新的內容不存在時候,不會添加 
        UpdateResponse response = client.prepareUpdate("twitter","tweet","1") 
                        .setDoc(jsonBuilder() 
                                 .startObject() 
                                   .field("users4","xue") 
                                 .endObject()) 
                                 .get();*/

        System.out.println(response.getVersion());


    }
 
開發者ID:hs-web,項目名稱:hsweb-learning,代碼行數:29,代碼來源:ElasticSearch.java

示例13: update

import org.elasticsearch.action.update.UpdateRequest; //導入方法依賴的package包/類
/**
 * 更新網頁
 *
 * @param webpage 網頁
 * @return
 */
public boolean update(Webpage webpage) throws ExecutionException, InterruptedException {
    UpdateRequest updateRequest = new UpdateRequest();
    updateRequest.index(INDEX_NAME);
    updateRequest.type(TYPE_NAME);
    updateRequest.id(webpage.getId());
    updateRequest.doc(gson.toJson(webpage));
    UpdateResponse response = client.update(updateRequest).get();
    return response.getResult() == UpdateResponse.Result.UPDATED;
}
 
開發者ID:bruceq,項目名稱:Gather-Platform,代碼行數:16,代碼來源:CommonWebpageDAO.java

示例14: internalAdd

import org.elasticsearch.action.update.UpdateRequest; //導入方法依賴的package包/類
BulkRequest internalAdd(UpdateRequest request, @Nullable Object payload) {
    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().getScript().length() * 2;
    }
    return this;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:15,代碼來源:BulkRequest.java

示例15: update

import org.elasticsearch.action.update.UpdateRequest; //導入方法依賴的package包/類
/**
 * 更新
 */
@Override
public String update(Person person) {
    UpdateRequest request = new UpdateRequest(index, type, person.getId());
    try {
        XContentBuilder builder = XContentFactory.jsonBuilder().startObject();
        if (person.getName() != null) {
            builder.field("name", person.getName());
        }
        if (person.getSex() != null) {
            builder.field("sex", person.getSex());
        }
        if (person.getIntroduce() != null) {
            builder.field("introduce", person.getIntroduce());
        }
        if (person.getBirthday() != null) {
            builder.field("birthday", person.getBirthday());
        }
        if (person.getAge() > 0) {
            builder.field("age", person.getAge());
        }
        builder.endObject();
        request.doc(builder);
        UpdateResponse response = transportClient.update(request).get();
        return response.getId();
    } catch (IOException | InterruptedException | ExecutionException e) {
        log.error(e.getMessage(), e);
    }
    return null;
}
 
開發者ID:jeikerxiao,項目名稱:SpringBootStudy,代碼行數:33,代碼來源:PersonDaoImpl.java


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