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


Java DeleteRequest.timeout方法代码示例

本文整理汇总了Java中org.elasticsearch.action.delete.DeleteRequest.timeout方法的典型用法代码示例。如果您正苦于以下问题:Java DeleteRequest.timeout方法的具体用法?Java DeleteRequest.timeout怎么用?Java DeleteRequest.timeout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.action.delete.DeleteRequest的用法示例。


在下文中一共展示了DeleteRequest.timeout方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: prepareRequest

import org.elasticsearch.action.delete.DeleteRequest; //导入方法依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    DeleteRequest deleteRequest = new DeleteRequest(request.param("index"), request.param("type"), request.param("id"));
    deleteRequest.routing(request.param("routing"));
    deleteRequest.parent(request.param("parent"));
    deleteRequest.timeout(request.paramAsTime("timeout", DeleteRequest.DEFAULT_TIMEOUT));
    deleteRequest.setRefreshPolicy(request.param("refresh"));
    deleteRequest.version(RestActions.parseVersion(request));
    deleteRequest.versionType(VersionType.fromString(request.param("version_type"), deleteRequest.versionType()));

    String waitForActiveShards = request.param("wait_for_active_shards");
    if (waitForActiveShards != null) {
        deleteRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards));
    }

    return channel -> client.delete(deleteRequest, new RestStatusToXContentListener<>(channel));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:RestDeleteAction.java

示例2: handleRequest

import org.elasticsearch.action.delete.DeleteRequest; //导入方法依赖的package包/类
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    DeleteRequest deleteRequest = new DeleteRequest(request.param("index"), request.param("type"), request.param("id"));
    deleteRequest.routing(request.param("routing"));
    deleteRequest.parent(request.param("parent")); // order is important, set it after routing, so it will set the routing
    deleteRequest.timeout(request.paramAsTime("timeout", DeleteRequest.DEFAULT_TIMEOUT));
    deleteRequest.refresh(request.paramAsBoolean("refresh", deleteRequest.refresh()));
    deleteRequest.version(RestActions.parseVersion(request));
    deleteRequest.versionType(VersionType.fromString(request.param("version_type"), deleteRequest.versionType()));

    String consistencyLevel = request.param("consistency");
    if (consistencyLevel != null) {
        deleteRequest.consistencyLevel(WriteConsistencyLevel.fromString(consistencyLevel));
    }

    client.delete(deleteRequest, new RestBuilderListener<DeleteResponse>(channel) {
        @Override
        public RestResponse buildResponse(DeleteResponse result, XContentBuilder builder) throws Exception {
            ActionWriteResponse.ShardInfo shardInfo = result.getShardInfo();
            builder.startObject().field(Fields.FOUND, result.isFound())
                    .field(Fields._INDEX, result.getIndex())
                    .field(Fields._TYPE, result.getType())
                    .field(Fields._ID, result.getId())
                    .field(Fields._VERSION, result.getVersion())
                    .value(shardInfo)
                    .endObject();
            RestStatus status = shardInfo.status();
            if (!result.isFound()) {
                status = NOT_FOUND;
            }
            return new BytesRestResponse(status, builder);
        }
    });
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:35,代码来源:RestDeleteAction.java

示例3: execute

import org.elasticsearch.action.delete.DeleteRequest; //导入方法依赖的package包/类
public void execute(final DeleteRequest request, final ActionListener<DeleteResponse> listener) {
    logger.debug("delete request " + request);
    try {
        RequestUriBuilder uriBuilder = new RequestUriBuilder(request.index(), request.type(), URLEncoder.encode(request.id(), Charsets.UTF_8.displayName()));

        uriBuilder.addQueryParameterIfNotZero("version", request.version());
        uriBuilder.addQueryParameterIfNotNull("routing", request.routing());

        uriBuilder.addVersionType(request.versionType());
        uriBuilder.addConsistencyLevel(request.consistencyLevel());

        if (request.refresh()) {
            uriBuilder.addQueryParameter("refresh", true);
        }
        if (request.timeout() != ShardReplicationOperationRequest.DEFAULT_TIMEOUT) {
            uriBuilder.addQueryParameter("timeout", request.timeout().toString());
        }

        httpClient.getHttpClient().submit(HttpClientRequest.createDelete(uriBuilder.toString()))
                .flatMap(ErrorHandler.AS_FUNC)
                .flatMap(new Func1<HttpClientResponse<ByteBuf>, Observable<DeleteResponse>>() {
                    @Override
                    public Observable<DeleteResponse> call(HttpClientResponse<ByteBuf> response) {
                        return response.getContent().flatMap(new Func1<ByteBuf, Observable<DeleteResponse>>() {
                            @Override
                            public Observable<DeleteResponse> call(ByteBuf byteBuf) {
                                return DeleteResponse.parse(byteBuf);
                            }
                        });
                    }
                })
                .single()
                .subscribe(new ListenerCompleterObserver<>(listener));
    } catch (Exception e) {
        listener.onFailure(e);
    }
}
 
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:38,代码来源:DeleteActionHandler.java

示例4: testDelete

import org.elasticsearch.action.delete.DeleteRequest; //导入方法依赖的package包/类
/**
 * This test documents docs/java-rest/high-level/document/delete.asciidoc
 */
public void testDelete() throws IOException {
    RestHighLevelClient client = highLevelClient();

    // tag::delete-request[]
    DeleteRequest request = new DeleteRequest(
        "index",    // <1>
        "type",     // <2>
        "id");      // <3>
    // end::delete-request[]

    // tag::delete-request-props[]
    request.timeout(TimeValue.timeValueSeconds(1));                     // <1>
    request.timeout("1s");                                              // <2>
    request.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL);    // <3>
    request.setRefreshPolicy("wait_for");                               // <4>
    request.version(2);                                                 // <5>
    request.versionType(VersionType.EXTERNAL);                          // <6>
    // end::delete-request-props[]

    // tag::delete-execute[]
    DeleteResponse response = client.delete(request);
    // end::delete-execute[]

    try {
        // tag::delete-notfound[]
        if (response.getResult().equals(DocWriteResponse.Result.NOT_FOUND)) {
            throw new Exception("Can't find document to be removed"); // <1>
        }
        // end::delete-notfound[]
    } catch (Exception ignored) { }

    // tag::delete-execute-async[]
    client.deleteAsync(request, new ActionListener<DeleteResponse>() {
        @Override
        public void onResponse(DeleteResponse deleteResponse) {
            // <1>
        }

        @Override
        public void onFailure(Exception e) {
            // <2>
        }
    });
    // end::delete-execute-async[]

    // tag::delete-conflict[]
    try {
        client.delete(request);
    } catch (ElasticsearchException exception) {
        if (exception.status().equals(RestStatus.CONFLICT)) {
            // <1>
        }
    }
    // end::delete-conflict[]

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:60,代码来源:DeleteDocumentationIT.java


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