本文整理汇总了Java中org.elasticsearch.action.update.UpdateRequestBuilder.get方法的典型用法代码示例。如果您正苦于以下问题:Java UpdateRequestBuilder.get方法的具体用法?Java UpdateRequestBuilder.get怎么用?Java UpdateRequestBuilder.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.action.update.UpdateRequestBuilder
的用法示例。
在下文中一共展示了UpdateRequestBuilder.get方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testInvalidUpdateScript
import org.elasticsearch.action.update.UpdateRequestBuilder; //导入方法依赖的package包/类
public void testInvalidUpdateScript() throws Exception {
try {
createIndex("test_index");
ensureGreen("test_index");
indexRandom(true, client().prepareIndex("test_index", "doc", "1").setSource("text_field", "text"));
UpdateRequestBuilder urb = client().prepareUpdate().setIndex("test_index");
urb.setType("doc");
urb.setId("1");
urb.setScript(new Script(ScriptType.INLINE, ExpressionScriptEngineService.NAME, "0", Collections.emptyMap()));
urb.get();
fail("Expression scripts should not be allowed to run as update scripts.");
} catch (Exception e) {
String message = e.getMessage();
assertThat(message + " should have contained failed to execute", message.contains("failed to execute"), equalTo(true));
message = e.getCause().getMessage();
assertThat(message + " should have contained not supported", message.contains("not supported"), equalTo(true));
}
}
示例2: upsertProduct
import org.elasticsearch.action.update.UpdateRequestBuilder; //导入方法依赖的package包/类
/**
* Upsert the given product into ES index.
*
* @param product given product object
*/
public void upsertProduct(Product product) throws InvalidProtocolBufferException {
log.debug("save product into ES");
final UpdateRequestBuilder updateRequestBuilder =
esClient
.prepareUpdate(INDEX, TYPE, String.valueOf(product.getProductId()))
.setDoc(
jsonPrinter
.includingDefaultValueFields()
.omittingInsignificantWhitespace()
.print(product)
)
.setDocAsUpsert(true);
updateRequestBuilder.get();
}
示例3: update
import org.elasticsearch.action.update.UpdateRequestBuilder; //导入方法依赖的package包/类
private UpdateResponse update(Boolean detectNoop, long expectedVersion, XContentBuilder xContentBuilder) {
UpdateRequestBuilder updateRequest = client().prepareUpdate("test", "type1", "1")
.setDoc(xContentBuilder)
.setDocAsUpsert(true)
.setFields("_source");
if (detectNoop != null) {
updateRequest.setDetectNoop(detectNoop);
}
UpdateResponse updateResponse = updateRequest.get();
assertThat(updateResponse.getGetResult(), notNullValue());
assertEquals(expectedVersion, updateResponse.getVersion());
return updateResponse;
}
示例4: patchObject
import org.elasticsearch.action.update.UpdateRequestBuilder; //导入方法依赖的package包/类
public UpdateResponse patchObject(String backendId, String type, String id, long version, ObjectNode object,
String updatedBy) {
object.with("meta").removeAll()//
.put("updatedBy", updatedBy)//
.put("updatedAt", DateTime.now().toString());
UpdateRequestBuilder update = Start.get().getElasticClient().prepareUpdate(backendId, type, id)
.setDoc(object.toString());
if (version > 0)
update.setVersion(version);
return update.get();
}
示例5: update
import org.elasticsearch.action.update.UpdateRequestBuilder; //导入方法依赖的package包/类
@Override
public IndexResponse update(
DocumentIdentifier id, UpdateScript script, UpdateOptions options, EzSecurityToken token)
throws TException {
// Ensure we can see the ID
ensureVisible(id, token);
if (!script.isSetScript()) {
final String errMsg = "No script was set for call to update()!";
logger.info(errMsg);
throw new TException(errMsg);
}
final UpdateRequestBuilder updateRequest =
client.prepareUpdate(indexName, id.getType(), id.getId()).setRefresh(true);
updateRequest.setScript(script.getScript());
if (script.isSetParameters()) {
for (final Map.Entry<String, String> entry : script.getParameters().entrySet()) {
updateRequest.addScriptParam(entry.getKey(), entry.getValue());
}
}
updateRequest.setRetryOnConflict(options.getRetryCount());
final UpdateResponse response = updateRequest.get();
return new IndexResponse().set_id(response.getId()).set_type(response.getType())
.set_version(response.getVersion()).setSuccess(true);
}
示例6: executeRequest
import org.elasticsearch.action.update.UpdateRequestBuilder; //导入方法依赖的package包/类
public void executeRequest(HistoryEvent historyEvent) {
try {
if (filterEvents(historyEvent)) {
return;
}
UpdateRequestBuilder updateRequestBuilder = prepareUpdateRequest(historyEvent);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(ElasticSearchHelper.convertRequestToJson(updateRequestBuilder.request()));
}
UpdateResponse updateResponse;
if (WAIT_FOR_RESPONSE > 0) {
updateResponse = updateRequestBuilder.get(TimeValue.timeValueSeconds(WAIT_FOR_RESPONSE));
} else {
updateResponse = updateRequestBuilder.get();
}
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("[" + updateResponse.getIndex() +
"][" + updateResponse.getType() +
"][update] process instance with id '" + updateResponse.getId() + "'");
LOGGER.log(Level.FINE, "Source: " + updateResponse.getGetResult().sourceAsString());
}
} catch (IOException e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
}
}