Java Code Examples for org.elasticsearch.action.update.UpdateRequestBuilder#setDetectNoop()

The following examples show how to use org.elasticsearch.action.update.UpdateRequestBuilder#setDetectNoop() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ESNestedSearchService.java    From search-spring-boot-starter with Apache License 2.0 6 votes vote down vote up
/**
 * 更新操作
 *
 * @param esObject es通用更新请求参数
 * @return <code>true</code> 保存或更新成功; 否则更新失败
 */
public SearchBaseResult<Boolean> update(UpdateESObject esObject) {
    final UpdateRequestBuilder updateRequest = esObject.nestedUpdate() ? getNestedListUpdateRequest(esObject)
            : getUpdateRequest(esObject);
    SearchLogger.log(updateRequest);
    try {
        updateRequest.setDetectNoop(false);
        if (esObject.isRefresh()) {
            updateRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL);
        }
        UpdateResponse updateResponse = updateRequest.execute().get();
        SearchLogger.log(updateResponse);
        final DocWriteResponse.Result result = updateResponse.getResult();
        return SearchBaseResult.success(DocWriteResponse.Result.UPDATED == result, Boolean.class);
    } catch (Exception ex) {
        SearchLogger.error("update", ex);
        final String message = ex.getMessage();
        if (message != null && message.contains("document missing")) {
            return SearchBaseResult.faild(ESErrorCode.DOC_NOT_EXIST_ERROR_CODE, "更新文档不存在");
        }
        return SearchBaseResult.faild(ESErrorCode.ELASTIC_ERROR_CODE, "esMsg:" + message);
    }
}
 
Example 2
Source File: DefaultElasticSearchService.java    From vertx-elasticsearch-service with Apache License 2.0 5 votes vote down vote up
private void populateUpdateRequestBuilder(UpdateRequestBuilder builder, UpdateOptions options) {
    if (options != null) {
        if (options.getRouting() != null) builder.setRouting(options.getRouting());
        if (options.getParent() != null) builder.setParent(options.getParent());
        if (options.getRefreshPolicy() != null)
            builder.setRefreshPolicy(WriteRequest.RefreshPolicy.valueOf(options.getRefreshPolicy().name()));
        if (options.getWaitForActiveShard() != null)
            builder.setWaitForActiveShards(options.getWaitForActiveShard());
        if (options.getVersion() != null) builder.setVersion(options.getVersion());
        if (options.getVersionType() != null) builder.setVersionType(options.getVersionType());
        if (options.getTimeout() != null) builder.setTimeout(options.getTimeout());

        if (options.getRetryOnConflict() != null) builder.setRetryOnConflict(options.getRetryOnConflict());
        if (options.getDoc() != null) builder.setDoc(options.getDoc().encode(), XContentType.JSON);
        if (options.getUpsert() != null) builder.setUpsert(options.getUpsert().encode(), XContentType.JSON);
        if (options.getDocAsUpsert() != null) builder.setDocAsUpsert(options.getDocAsUpsert());
        if (options.getDetectNoop() != null) builder.setDetectNoop(options.getDetectNoop());
        if (options.getScriptedUpsert() != null) builder.setScriptedUpsert(options.getScriptedUpsert());

        if (options.getScript() != null) {
            builder.setScript(createScript(Optional.ofNullable(options.getScriptType()), Optional.ofNullable(options.getScriptLang()), Optional.ofNullable(options.getScriptParams()), options.getScript()));

        }
        if (!options.getFields().isEmpty()) {
            builder.setFields(options.getFields().toArray(new String[options.getFields().size()]));
        }
    }
}