本文整理汇总了Java中org.elasticsearch.action.update.UpdateRequestBuilder类的典型用法代码示例。如果您正苦于以下问题:Java UpdateRequestBuilder类的具体用法?Java UpdateRequestBuilder怎么用?Java UpdateRequestBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UpdateRequestBuilder类属于org.elasticsearch.action.update包,在下文中一共展示了UpdateRequestBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: batchPersistence
import org.elasticsearch.action.update.UpdateRequestBuilder; //导入依赖的package包/类
@Override public void batchPersistence(List<?> batchCollection) {
BulkRequestBuilder bulkRequest = getClient().prepareBulk();
logger.debug("bulk data size: {}", batchCollection.size());
if (CollectionUtils.isNotEmpty(batchCollection)) {
batchCollection.forEach(builder -> {
if (builder instanceof IndexRequestBuilder) {
bulkRequest.add((IndexRequestBuilder)builder);
}
if (builder instanceof UpdateRequestBuilder) {
bulkRequest.add((UpdateRequestBuilder)builder);
}
});
BulkResponse bulkResponse = bulkRequest.execute().actionGet();
if (bulkResponse.hasFailures()) {
logger.error(bulkResponse.buildFailureMessage());
}
}
}
示例2: removeFieldsFromDocument
import org.elasticsearch.action.update.UpdateRequestBuilder; //导入依赖的package包/类
/**
* Helper method to remove fields from source. This method will generate a ES update request. Retries on conflict.
*
* @param graph Graph object configured with the index names
* @param element Element that can be mapped to an ES document
* @param fields fields to remove
*/
private void removeFieldsFromDocument(Graph graph, Element element, Collection<String> fields) {
if (fields == null || fields.isEmpty()) {
return;
}
List<String> fieldNames = fields.stream().map(field -> field.replace(".", FIELDNAME_DOT_REPLACEMENT)).collect(Collectors.toList());
if (fieldNames.isEmpty()) {
return;
}
UpdateRequestBuilder updateRequestBuilder = getClient().prepareUpdate()
.setIndex(getIndexName(element))
.setId(element.getId())
.setType(ELEMENT_TYPE)
.setScript(new Script(
ScriptType.INLINE,
"painless",
"for (def fieldName : params.fieldNames) { ctx._source.remove(fieldName); }",
ImmutableMap.of("fieldNames", fieldNames)
))
.setRetryOnConflict(MAX_RETRIES);
addActionRequestBuilderForFlush(element.getId(), updateRequestBuilder);
if (getConfig().isAutoFlush()) {
flush(graph);
}
}
示例3: 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));
}
}
示例4: batchUpdate
import org.elasticsearch.action.update.UpdateRequestBuilder; //导入依赖的package包/类
/**
* 批量更新
*
* @param transportClient
*/
private static void batchUpdate(TransportClient transportClient) throws IOException {
BulkRequestBuilder bulkRequestBuilder = transportClient.prepareBulk();
UpdateRequestBuilder updateRequestBuilder1 = transportClient.prepareUpdate("product_index", "product", "1")
.setDoc(XContentFactory.jsonBuilder()
.startObject()
.field("product_name", "更新后的商品名称1")
.endObject());
UpdateRequestBuilder updateRequestBuilder2 = transportClient.prepareUpdate("product_index", "product", "2")
.setDoc(XContentFactory.jsonBuilder()
.startObject()
.field("product_name", "更新后的商品名称2")
.endObject());
UpdateRequestBuilder updateRequestBuilder3 = transportClient.prepareUpdate("product_index", "product", "3")
.setDoc(XContentFactory.jsonBuilder()
.startObject()
.field("product_name", "更新后的商品名称3")
.endObject());
bulkRequestBuilder.add(updateRequestBuilder1);
bulkRequestBuilder.add(updateRequestBuilder2);
bulkRequestBuilder.add(updateRequestBuilder3);
BulkResponse bulkResponse = bulkRequestBuilder.get();
for (BulkItemResponse bulkItemResponse : bulkResponse.getItems()) {
logger.info("--------------------------------version= " + bulkItemResponse.getVersion());
}
}
示例5: execute
import org.elasticsearch.action.update.UpdateRequestBuilder; //导入依赖的package包/类
/**
* Executes the list with requests as a bulk with maximum number of requests per bulk
* @param requests
* @param maxRequestsPerBulk
* @return
* @throws SQLException
*/
private int execute(List<?> requests, int maxRequestsPerBulk) throws SQLException{
int result = 0;
BulkRequestBuilder bulkReq = client.prepareBulk();
for(Object req : requests){
if(req instanceof IndexRequest) bulkReq.add((IndexRequest)req);
else if(req instanceof UpdateRequest) bulkReq.add((UpdateRequest)req);
else if(req instanceof DeleteRequest) bulkReq.add((DeleteRequest)req);
else if(req instanceof IndexRequestBuilder) bulkReq.add((IndexRequestBuilder)req);
else if(req instanceof UpdateRequestBuilder) bulkReq.add((UpdateRequestBuilder)req);
else if(req instanceof DeleteRequestBuilder) bulkReq.add((DeleteRequestBuilder)req);
else throw new SQLException("Type "+req.getClass()+" cannot be added to a bulk request");
if(bulkReq.numberOfActions() > maxRequestsPerBulk){
result += bulkReq.get().getItems().length;
bulkReq = client.prepareBulk();
}
}
if(bulkReq.numberOfActions() > 0){
result += bulkReq.get().getItems().length;
}
return result;
}
示例6: prepareBatchUpdate
import org.elasticsearch.action.update.UpdateRequestBuilder; //导入依赖的package包/类
@Override public UpdateRequestBuilder prepareBatchUpdate(ServiceReferenceAlarm data) {
Map<String, Object> source = new HashMap<>();
source.put(ServiceReferenceAlarmTable.COLUMN_FRONT_APPLICATION_ID, data.getFrontApplicationId());
source.put(ServiceReferenceAlarmTable.COLUMN_BEHIND_APPLICATION_ID, data.getBehindApplicationId());
source.put(ServiceReferenceAlarmTable.COLUMN_FRONT_INSTANCE_ID, data.getFrontInstanceId());
source.put(ServiceReferenceAlarmTable.COLUMN_BEHIND_INSTANCE_ID, data.getBehindInstanceId());
source.put(ServiceReferenceAlarmTable.COLUMN_FRONT_SERVICE_ID, data.getFrontServiceId());
source.put(ServiceReferenceAlarmTable.COLUMN_BEHIND_SERVICE_ID, data.getBehindServiceId());
source.put(ServiceReferenceAlarmTable.COLUMN_SOURCE_VALUE, data.getSourceValue());
source.put(ServiceReferenceAlarmTable.COLUMN_ALARM_TYPE, data.getAlarmType());
source.put(ServiceReferenceAlarmTable.COLUMN_ALARM_CONTENT, data.getAlarmContent());
source.put(ServiceReferenceAlarmTable.COLUMN_LAST_TIME_BUCKET, data.getLastTimeBucket());
return getClient().prepareUpdate(ServiceReferenceAlarmTable.TABLE, data.getId()).setDoc(source);
}
示例7: prepareBatchUpdate
import org.elasticsearch.action.update.UpdateRequestBuilder; //导入依赖的package包/类
@Override public UpdateRequestBuilder prepareBatchUpdate(ServiceReferenceAlarmList data) {
Map<String, Object> source = new HashMap<>();
source.put(ServiceReferenceAlarmListTable.COLUMN_FRONT_APPLICATION_ID, data.getFrontApplicationId());
source.put(ServiceReferenceAlarmListTable.COLUMN_BEHIND_APPLICATION_ID, data.getBehindApplicationId());
source.put(ServiceReferenceAlarmListTable.COLUMN_FRONT_INSTANCE_ID, data.getFrontInstanceId());
source.put(ServiceReferenceAlarmListTable.COLUMN_BEHIND_INSTANCE_ID, data.getBehindInstanceId());
source.put(ServiceReferenceAlarmListTable.COLUMN_FRONT_SERVICE_ID, data.getFrontServiceId());
source.put(ServiceReferenceAlarmListTable.COLUMN_BEHIND_SERVICE_ID, data.getBehindServiceId());
source.put(ServiceReferenceAlarmListTable.COLUMN_SOURCE_VALUE, data.getSourceValue());
source.put(ServiceReferenceAlarmListTable.COLUMN_ALARM_TYPE, data.getAlarmType());
source.put(ServiceReferenceAlarmListTable.COLUMN_ALARM_CONTENT, data.getAlarmContent());
source.put(ServiceReferenceAlarmListTable.COLUMN_TIME_BUCKET, data.getTimeBucket());
return getClient().prepareUpdate(ServiceReferenceAlarmListTable.TABLE, data.getId()).setDoc(source);
}
示例8: update
import org.elasticsearch.action.update.UpdateRequestBuilder; //导入依赖的package包/类
public boolean update(String typeName, String id, Map<String, Object> data,
boolean upset) throws SearchException {
if (data == null || data.size() == 0) {
return false;
}
Timer.Context timer = searchMetrics.indexTimer(typeName, "updateMap");
try {
String jsonSource = this.docMapper.toJSON(data, true);
UpdateRequestBuilder request = client.prepareUpdate(indexName,
typeName, id).setId(id);
if (upset) {
request.setDocAsUpsert(true);
}
request.setDoc(jsonSource);
request.execute().actionGet();
searchMetrics.indexIncr(typeName, "updateMap");
return true;
} catch (Exception e) {
searchMetrics.failedIncr(typeName, "updateMap", e);
logger.error("update index Error. ", e);
throw new SearchException("update index Error. typeName="+typeName+", id="+id, e);
}finally {
timer.stop();
}
}
示例9: addElementWithScript
import org.elasticsearch.action.update.UpdateRequestBuilder; //导入依赖的package包/类
private void addElementWithScript(
Graph graph,
final Element element,
Authorizations authorizations
) {
if (MUTATION_LOGGER.isTraceEnabled()) {
MUTATION_LOGGER.trace("addElement: %s", element.getId());
}
if (!getConfig().isIndexEdges() && element instanceof Edge) {
return;
}
final IndexInfo indexInfo = addPropertiesToIndex(graph, element, element.getProperties());
try {
final XContentBuilder source = buildJsonContentFromElement(graph, element, authorizations);
if (MUTATION_LOGGER.isTraceEnabled()) {
MUTATION_LOGGER.trace("addElement json: %s: %s", element.getId(), source.string());
}
if (flushObjectQueueContainsElementId(element.getId())) {
flushFlushObjectQueue();
}
UpdateRequestBuilder updateRequestBuilder = getClient()
.prepareUpdate(indexInfo.getIndexName(), ELEMENT_TYPE, element.getId())
.setDocAsUpsert(true)
.setDoc(source)
.setRetryOnConflict(MAX_RETRIES);
addActionRequestBuilderForFlush(element.getId(), updateRequestBuilder);
if (getConfig().isAutoFlush()) {
flush(graph);
}
} catch (Exception e) {
throw new MemgraphException("Could not add element", e);
}
getConfig().getScoringStrategy().addElement(this, graph, element, authorizations);
}
示例10: addActionRequestBuilderForFlush
import org.elasticsearch.action.update.UpdateRequestBuilder; //导入依赖的package包/类
private void addActionRequestBuilderForFlush(String elementId, UpdateRequestBuilder updateRequestBuilder) {
Future future;
try {
future = updateRequestBuilder.execute();
} catch (Exception ex) {
LOGGER.debug("Could not execute update: %s", ex.getMessage());
future = SettableFuture.create();
((SettableFuture) future).setException(ex);
}
getFlushObjectQueue().add(new FlushObject(elementId, updateRequestBuilder, future));
}
示例11: addElementExtendedData
import org.elasticsearch.action.update.UpdateRequestBuilder; //导入依赖的package包/类
private void addElementExtendedData(
Graph graph,
Element element,
String tableName,
String rowId,
List<ExtendedDataMutation> columns,
Authorizations authorizations
) {
if (MUTATION_LOGGER.isTraceEnabled()) {
MUTATION_LOGGER.trace("addElementExtendedData: %s:%s:%s", element.getId(), tableName, rowId);
}
final IndexInfo indexInfo = addExtendedDataColumnsToIndex(graph, element, tableName, rowId, columns);
try {
final XContentBuilder jsonBuilder = buildJsonContentFromExtendedDataMutations(graph, element, tableName, rowId, columns, authorizations);
final XContentBuilder source = jsonBuilder.endObject();
if (MUTATION_LOGGER.isTraceEnabled()) {
MUTATION_LOGGER.trace("addElementExtendedData json: %s:%s:%s: %s", element.getId(), tableName, rowId, source.string());
}
String extendedDataDocId = ElasticsearchExtendedDataIdUtils.createForElement(element, tableName, rowId);
UpdateRequestBuilder updateRequestBuilder = getClient()
.prepareUpdate(indexInfo.getIndexName(), ELEMENT_TYPE, extendedDataDocId)
.setDocAsUpsert(true)
.setDoc(source)
.setRetryOnConflict(MAX_RETRIES);
addActionRequestBuilderForFlush(element.getId(), updateRequestBuilder);
if (getConfig().isAutoFlush()) {
flush(graph);
}
} catch (Exception e) {
throw new MemgraphException("Could not add element extended data", e);
}
getConfig().getScoringStrategy().addElementExtendedData(this, graph, element, tableName, rowId, columns, authorizations);
}
示例12: FlushObject
import org.elasticsearch.action.update.UpdateRequestBuilder; //导入依赖的package包/类
FlushObject(
String elementId,
UpdateRequestBuilder updateRequestBuilder,
Future future
) {
this(elementId, updateRequestBuilder, future, 0, System.currentTimeMillis());
}
示例13: 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();
}
示例14: 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;
}
示例15: upsertUrlStatus
import org.elasticsearch.action.update.UpdateRequestBuilder; //导入依赖的package包/类
public void upsertUrlStatus(String url, String published, String source, boolean create, Enum status) throws IOException {
Date now = new Date();
IndexRequestBuilder insert = getConnection().getClient()
.prepareIndex(getIndex(), getType(), url)
.setSource(jsonBuilder()
.startObject()
.field("url", url)
.field("source", source)
.field("created", now)
.field("updated", now)
.field("published", published)
.field("status", String.valueOf(status))
.endObject())
.setCreate(create);
UpdateRequestBuilder update = getConnection().getClient()
.prepareUpdate(getIndex(), getType(), url)
.setDoc(jsonBuilder()
.startObject()
.field("updated", now)
.field("published", published)
.field("status", String.valueOf(status))
.endObject())
.setUpsert(insert.request());
getConnection().getProcessor().add(create ? insert.request() : update.request());
}