本文整理汇总了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);
}
}
示例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));
}
示例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;
}
示例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);
}
}
示例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();
}
示例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);
}
}
示例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);
}
}
示例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");
}
示例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");
}
示例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);
}
示例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;
}
示例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());
}
示例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;
}
示例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;
}
示例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;
}