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


Java MultiGetRequest.Item方法代码示例

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


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

示例1: should_get_documents_without_source

import org.elasticsearch.action.get.MultiGetRequest; //导入方法依赖的package包/类
@Test
public void should_get_documents_without_source() throws IOException, ExecutionException, InterruptedException {
    BytesReference source = source().bytes();

    createDoc(THE_INDEX, THE_TYPE, THE_ID, source.toUtf8());

    MultiGetRequest.Item item = new MultiGetRequest.Item(THE_INDEX, THE_TYPE, THE_ID).fields("the_string_field").fetchSourceContext(FetchSourceContext.DO_NOT_FETCH_SOURCE);
    MultiGetRequest multiGetRequest = new MultiGetRequest().add(item);
    MultiGetResponse response = httpClient.multiGet(multiGetRequest).get();

    Assertions.assertThat(response.all()).hasSize(1);
    Assertions.assertThat(response.errors()).hasSize(0);

    Assertions.assertThat(response.documents().get(0).getSource()).isNull();
    Assertions.assertThat(response.documents().get(0).getFields()).hasSize(1).containsKey("the_string_field");
}
 
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:17,代码来源:MultiGetActionHandlerTest.java

示例2: should_get_document_version

import org.elasticsearch.action.get.MultiGetRequest; //导入方法依赖的package包/类
@Test
public void should_get_document_version() throws IOException, ExecutionException, InterruptedException {
    BytesReference source = source().bytes();

    createDoc(THE_INDEX, THE_TYPE, THE_ID, source.toUtf8());
    createDoc(THE_INDEX, THE_TYPE, THE_ID, source.toUtf8());

    MultiGetRequest.Item item = new MultiGetRequest.Item(THE_INDEX, THE_TYPE, THE_ID)
            .version(2)
            .fields("the_string_field")
            .fetchSourceContext(FetchSourceContext.DO_NOT_FETCH_SOURCE);
    MultiGetRequest multiGetRequest = new MultiGetRequest().add(item);
    MultiGetResponse response = httpClient.multiGet(multiGetRequest).get();

    Assertions.assertThat(response.all()).hasSize(1);
    Assertions.assertThat(response.errors()).hasSize(0);

    Assertions.assertThat(response.documents().get(0).getVersion()).isEqualTo(2);
}
 
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:20,代码来源:MultiGetActionHandlerTest.java

示例3: should_fail_when_version_different

import org.elasticsearch.action.get.MultiGetRequest; //导入方法依赖的package包/类
@Test
public void should_fail_when_version_different() throws IOException, InterruptedException, ExecutionException {
    BytesReference source = source().bytes();

    createDoc(THE_INDEX, THE_TYPE, THE_ID, source.toUtf8());
    createDoc(THE_INDEX, THE_TYPE, THE_ID, source.toUtf8());

    MultiGetRequest.Item item = new MultiGetRequest.Item(THE_INDEX, THE_TYPE, THE_ID)
            .version(1)
            .fields("the_string_field")
            .fetchSourceContext(FetchSourceContext.DO_NOT_FETCH_SOURCE);
    MultiGetRequest multiGetRequest = new MultiGetRequest().add(item);
    MultiGetResponse response = httpClient.multiGet(multiGetRequest).get();

    Assertions.assertThat(response.all()).hasSize(1);
    List<MultiGetResponseError> errors = response.errors();
    Assertions.assertThat(errors).hasSize(1);

    Assertions.assertThat(errors.get(0).getIndex()).isEqualTo(THE_INDEX);
    Assertions.assertThat(errors.get(0).getType()).isEqualTo(THE_TYPE);
    Assertions.assertThat(errors.get(0).getId()).isEqualTo(THE_ID);
    Assertions.assertThat(errors.get(0).getError()).contains("VersionConflictEngineException[[the_index]") // skip the shard number
            .contains("[the_type][the_id]: version conflict, current [2], provided [1]]");
}
 
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:25,代码来源:MultiGetActionHandlerTest.java

示例4: TermVectorsRequest

import org.elasticsearch.action.get.MultiGetRequest; //导入方法依赖的package包/类
public TermVectorsRequest(MultiGetRequest.Item item) {
    super(item.index());
    this.id = item.id();
    this.type = item.type();
    this.selectedFields(item.storedFields());
    this.routing(item.routing());
    this.parent(item.parent());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:TermVectorsRequest.java

示例5: multiGetDocument

import org.elasticsearch.action.get.MultiGetRequest; //导入方法依赖的package包/类
private GetResponse multiGetDocument(String index, String type, String docId, String field, @Nullable String routing) {
  MultiGetRequest.Item getItem = new MultiGetRequest.Item(index, type, docId).storedFields(field);
    if (routing != null) {
        getItem.routing(routing);
    }
    MultiGetRequestBuilder multiGetRequestBuilder = client().prepareMultiGet().add(getItem);
    MultiGetResponse multiGetResponse = multiGetRequestBuilder.get();
    assertThat(multiGetResponse.getResponses().length, equalTo(1));
    return multiGetResponse.getResponses()[0].getResponse();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:GetActionIT.java

示例6: TermVectorsRequest

import org.elasticsearch.action.get.MultiGetRequest; //导入方法依赖的package包/类
public TermVectorsRequest(MultiGetRequest.Item item) {
    super(item.index());
    this.id = item.id();
    this.type = item.type();
    this.selectedFields(item.fields());
    this.routing(item.routing());
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:8,代码来源:TermVectorsRequest.java

示例7: toMultiGetRequest

import org.elasticsearch.action.get.MultiGetRequest; //导入方法依赖的package包/类
@Converter
public static MultiGetRequest toMultiGetRequest(Object document, Exchange exchange) {
    List<Item> items = (List<Item>) document;
    MultiGetRequest multiGetRequest = new MultiGetRequest();
    Iterator<Item> it = items.iterator();
    while (it.hasNext()) {
        MultiGetRequest.Item item = it.next();
        multiGetRequest.add(item);
    }
    return multiGetRequest;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:12,代码来源:ElasticsearchActionRequestConverter.java

示例8: execute

import org.elasticsearch.action.get.MultiGetRequest; //导入方法依赖的package包/类
public void execute(final MultiGetRequest request, final ActionListener<MultiGetResponse> listener) {
    logger.debug("multi get request {}", request);
    try {
        RequestUriBuilder uriBuilder = new RequestUriBuilder().addEndpoint("_mget");

        uriBuilder.addQueryParameter("ignore_errors_on_generated_fields", request.ignoreErrorsOnGeneratedFields);
        uriBuilder.addQueryParameterIfNotNull("preference", request.preference());
        uriBuilder.addQueryParameterIfNotNull("refresh", request.refresh());
        uriBuilder.addQueryParameterIfNotNull("realtime", request.realtime());

        XContentBuilder builder = XContentFactory.jsonBuilder();
        builder.startObject().field("docs").startArray();
        for (MultiGetRequest.Item item : request.getItems()) {
            writeItem(builder, item);
        }
        builder.endArray().endObject();

        httpClient.getHttpClient().submit(HttpClientRequest.createPost(uriBuilder.toString())
                .withContent(builder.bytes().toBytes()))
                .flatMap(ErrorHandler.AS_FUNC)
                .flatMap(new Func1<HttpClientResponse<ByteBuf>, Observable<MultiGetResponse>>() {
                    @Override
                    public Observable<MultiGetResponse> call(HttpClientResponse<ByteBuf> response) {
                        return response.getContent().flatMap(new Func1<ByteBuf, Observable<MultiGetResponse>>() {
                            @Override
                            public Observable<MultiGetResponse> call(ByteBuf byteBuf) {
                                return MultiGetResponse.parse(byteBuf);
                            }
                        });
                    }
                })
                .single()
                .subscribe(new ListenerCompleterObserver<>(listener));

    } catch (Exception e) {
        listener.onFailure(e);
    }
}
 
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:39,代码来源:MultiGetActionHandler.java

示例9: writeItem

import org.elasticsearch.action.get.MultiGetRequest; //导入方法依赖的package包/类
private void writeItem(XContentBuilder builder, MultiGetRequest.Item item) throws IOException {
    builder.startObject();
    builder.field("_index", item.index());
    builder.field("_type", item.type());
    builder.field("_id", item.id());
    FetchSourceContext fetchSourceContext = item.fetchSourceContext();
    if(fetchSourceContext != null) {
        if(fetchSourceContext.fetchSource()) {
            if(fetchSourceContext.includes().length != 0 | fetchSourceContext.excludes().length != 0) {
                builder.startObject("_source");
                if(fetchSourceContext.includes().length != 0) {
                    builder.array("include", fetchSourceContext.includes());
                }
                if(fetchSourceContext.excludes().length != 0) {
                    builder.array("exclude", fetchSourceContext.excludes());

                }
                builder.endObject();
            }
        } else {
            builder.field("_source", false);
        }
    }
    if(item.fields() != null && item.fields().length != 0) {
        builder.array("fields", item.fields());
    }
    if(item.routing() != null) {
        builder.array("_routing", item.routing());
    }

    if(item.indicesOptions() != null) {
        builder.array("_routing", item.routing());
    }
    if(item.versionType() != VersionType.INTERNAL) {
        builder.array("_version_type", item.versionType().name().toLowerCase());
    }
    if(item.version() != Versions.MATCH_ANY) {
        builder.array("_version", item.version());
    }

    builder.endObject();
}
 
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:43,代码来源:MultiGetActionHandler.java


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