当前位置: 首页>>代码示例>>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;未经允许,请勿转载。