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