当前位置: 首页>>代码示例>>Java>>正文


Java UpdateRequestBuilder类代码示例

本文整理汇总了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());
        }
    }
}
 
开发者ID:apache,项目名称:incubator-skywalking,代码行数:21,代码来源:BatchEsDAO.java

示例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);
    }
}
 
开发者ID:mware-solutions,项目名称:memory-graph,代码行数:36,代码来源:Elasticsearch5SearchIndex.java

示例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));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:MoreExpressionTests.java

示例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());
	}
}
 
开发者ID:judasn,项目名称:Elasticsearch-Tutorial-zh-CN,代码行数:37,代码来源:BaseDemo.java

示例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;
}
 
开发者ID:Anchormen,项目名称:sql4es,代码行数:31,代码来源:ESUpdateState.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-skywalking,代码行数:18,代码来源:ServiceReferenceAlarmEsPersistenceDAO.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-skywalking,代码行数:18,代码来源:ServiceReferenceAlarmListEsPersistenceDAO.java

示例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();
      }
  }
 
开发者ID:yamingd,项目名称:argo,代码行数:26,代码来源:ElasticSearchTemplate.java

示例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);
}
 
开发者ID:mware-solutions,项目名称:memory-graph,代码行数:41,代码来源:Elasticsearch5SearchIndex.java

示例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));
}
 
开发者ID:mware-solutions,项目名称:memory-graph,代码行数:12,代码来源:Elasticsearch5SearchIndex.java

示例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);
}
 
开发者ID:mware-solutions,项目名称:memory-graph,代码行数:39,代码来源:Elasticsearch5SearchIndex.java

示例12: FlushObject

import org.elasticsearch.action.update.UpdateRequestBuilder; //导入依赖的package包/类
FlushObject(
        String elementId,
        UpdateRequestBuilder updateRequestBuilder,
        Future future
) {
    this(elementId, updateRequestBuilder, future, 0, System.currentTimeMillis());
}
 
开发者ID:mware-solutions,项目名称:memory-graph,代码行数:8,代码来源:Elasticsearch5SearchIndex.java

示例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();
}
 
开发者ID:email2liyang,项目名称:grpc-mate,代码行数:20,代码来源:ProductDao.java

示例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;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:UpdateNoopIT.java

示例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());
}
 
开发者ID:tokenmill,项目名称:crawling-framework,代码行数:28,代码来源:EsHttpUrlOperations.java


注:本文中的org.elasticsearch.action.update.UpdateRequestBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。