• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java MultiGetRequest类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: prepareRequest

import org.elasticsearch.action.get.MultiGetRequest; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    MultiGetRequest multiGetRequest = new MultiGetRequest();
    multiGetRequest.refresh(request.paramAsBoolean("refresh", multiGetRequest.refresh()));
    multiGetRequest.preference(request.param("preference"));
    multiGetRequest.realtime(request.paramAsBoolean("realtime", multiGetRequest.realtime()));
    if (request.param("fields") != null) {
        throw new IllegalArgumentException("The parameter [fields] is no longer supported, " +
            "please use [stored_fields] to retrieve stored fields or _source filtering if the field is not stored");
    }
    String[] sFields = null;
    String sField = request.param("stored_fields");
    if (sField != null) {
        sFields = Strings.splitStringByCommaToArray(sField);
    }

    FetchSourceContext defaultFetchSource = FetchSourceContext.parseFromRestRequest(request);
    try (XContentParser parser = request.contentOrSourceParamParser()) {
        multiGetRequest.add(request.param("index"), request.param("type"), sFields, defaultFetchSource,
            request.param("routing"), parser, allowExplicitIndex);
    }

    return channel -> client.multiGet(multiGetRequest, new RestToXContentListener<>(channel));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:RestMultiGetAction.java


示例2: testMultiGet

import org.elasticsearch.action.get.MultiGetRequest; //导入依赖的package包/类
public void testMultiGet() {
    String multiGetShardAction = MultiGetAction.NAME + "[shard][s]";
    interceptTransportActions(multiGetShardAction);

    List<String> indices = new ArrayList<>();
    MultiGetRequest multiGetRequest = new MultiGetRequest();
    int numDocs = iterations(1, 30);
    for (int i = 0; i < numDocs; i++) {
        String indexOrAlias = randomIndexOrAlias();
        multiGetRequest.add(indexOrAlias, "type", Integer.toString(i));
        indices.add(indexOrAlias);
    }
    internalCluster().coordOnlyNodeClient().multiGet(multiGetRequest).actionGet();

    clearInterceptedActions();
    assertIndicesSubset(indices, multiGetShardAction);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:IndicesRequestIT.java


示例3: handleRequest

import org.elasticsearch.action.get.MultiGetRequest; //导入依赖的package包/类
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception {
    MultiGetRequest multiGetRequest = new MultiGetRequest();
    multiGetRequest.refresh(request.paramAsBoolean("refresh", multiGetRequest.refresh()));
    multiGetRequest.preference(request.param("preference"));
    multiGetRequest.realtime(request.paramAsBoolean("realtime", null));
    multiGetRequest.ignoreErrorsOnGeneratedFields(request.paramAsBoolean("ignore_errors_on_generated_fields", false));

    String[] sFields = null;
    String sField = request.param("fields");
    if (sField != null) {
        sFields = Strings.splitStringByCommaToArray(sField);
    }

    FetchSourceContext defaultFetchSource = FetchSourceContext.parseFromRestRequest(request);
    multiGetRequest.add(request.param("index"), request.param("type"), sFields, defaultFetchSource, request.param("routing"), RestActions.getRestContent(request), allowExplicitIndex);

    client.multiGet(multiGetRequest, new RestToXContentListener<MultiGetResponse>(channel));
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:20,代码来源:RestMultiGetAction.java


示例4: toMultiSearchRequest

import org.elasticsearch.action.get.MultiGetRequest; //导入依赖的package包/类
protected MultiSearchRequest toMultiSearchRequest(final MultiGetRequest multiGetRequest) {

        final MultiSearchRequest msearch = new MultiSearchRequest();
        msearch.copyContextFrom(multiGetRequest);

        for (final Iterator<Item> iterator = multiGetRequest.iterator(); iterator.hasNext();) {
            final Item item = iterator.next();

            final SearchRequest st = new SearchRequest();
            st.routing(item.routing());
            st.indices(item.indices());
            st.types(item.type());
            st.preference(multiGetRequest.preference());
            st.source(SearchSourceBuilder.searchSource().query(new IdsQueryBuilder(item.type()).addIds(item.id())));
            msearch.add(st);
        }

        return msearch;

    }
 
开发者ID:petalmd,项目名称:armor,代码行数:21,代码来源:AbstractActionFilter.java


示例5: should_get_several_documents

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

    createDoc(THE_INDEX, THE_TYPE, THE_ID, source.toUtf8());
    createDoc(THE_INDEX, THE_TYPE, "2", source.toUtf8());
    createDoc(THE_INDEX, THE_TYPE, "3", source.toUtf8());

    MultiGetRequest multiGetRequest = new MultiGetRequest()
            .add(THE_INDEX, THE_TYPE, THE_ID)
            .add(THE_INDEX, THE_TYPE, "2")
            .add(THE_INDEX, THE_TYPE, "3");
    MultiGetResponse response = httpClient.multiGet(multiGetRequest).get();

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

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


示例6: 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


示例7: 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


示例8: 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


示例9: 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


示例10: assertGetFieldException

import org.elasticsearch.action.get.MultiGetRequest; //导入依赖的package包/类
private void assertGetFieldException(String index, String type, String docId, String field) {
    try {
        client().prepareGet().setIndex(index).setType(type).setId(docId).setStoredFields(field);
        fail();
    } catch (ElasticsearchException e) {
        assertTrue(e.getMessage().contains("You can only get this field after refresh() has been called."));
    }
    MultiGetResponse multiGetResponse = client().prepareMultiGet().add(new MultiGetRequest.Item(index, type, docId).storedFields(field)).get();
    assertNull(multiGetResponse.getResponses()[0].getResponse());
    assertTrue(multiGetResponse.getResponses()[0].getFailure().getMessage().contains("You can only get this field after refresh() has been called."));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:GetActionIT.java


示例11: 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


示例12: testThatMgetShouldWorkWithOneIndexMissing

import org.elasticsearch.action.get.MultiGetRequest; //导入依赖的package包/类
public void testThatMgetShouldWorkWithOneIndexMissing() throws IOException {
    createIndex("test");

    client().prepareIndex("test", "test", "1").setSource(jsonBuilder().startObject().field("foo", "bar").endObject())
            .setRefreshPolicy(IMMEDIATE).get();

    MultiGetResponse mgetResponse = client().prepareMultiGet()
            .add(new MultiGetRequest.Item("test", "test", "1"))
            .add(new MultiGetRequest.Item("nonExistingIndex", "test", "1"))
            .get();
    assertThat(mgetResponse.getResponses().length, is(2));

    assertThat(mgetResponse.getResponses()[0].getIndex(), is("test"));
    assertThat(mgetResponse.getResponses()[0].isFailed(), is(false));

    assertThat(mgetResponse.getResponses()[1].getIndex(), is("nonExistingIndex"));
    assertThat(mgetResponse.getResponses()[1].isFailed(), is(true));
    assertThat(mgetResponse.getResponses()[1].getFailure().getMessage(), is("no such index"));
    assertThat(((ElasticsearchException) mgetResponse.getResponses()[1].getFailure().getFailure()).getIndex().getName(),
        is("nonExistingIndex"));

    mgetResponse = client().prepareMultiGet()
            .add(new MultiGetRequest.Item("nonExistingIndex", "test", "1"))
            .get();
    assertThat(mgetResponse.getResponses().length, is(1));
    assertThat(mgetResponse.getResponses()[0].getIndex(), is("nonExistingIndex"));
    assertThat(mgetResponse.getResponses()[0].isFailed(), is(true));
    assertThat(mgetResponse.getResponses()[0].getFailure().getMessage(), is("no such index"));
    assertThat(((ElasticsearchException) mgetResponse.getResponses()[0].getFailure().getFailure()).getIndex().getName(),
        is("nonExistingIndex"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:32,代码来源:SimpleMgetIT.java


示例13: testThatMgetShouldWorkWithMultiIndexAlias

import org.elasticsearch.action.get.MultiGetRequest; //导入依赖的package包/类
public void testThatMgetShouldWorkWithMultiIndexAlias() throws IOException {
    assertAcked(prepareCreate("test").addAlias(new Alias("multiIndexAlias")));
    assertAcked(prepareCreate("test2").addAlias(new Alias("multiIndexAlias")));

    client().prepareIndex("test", "test", "1").setSource(jsonBuilder().startObject().field("foo", "bar").endObject())
        .setRefreshPolicy(IMMEDIATE).get();

    MultiGetResponse mgetResponse = client().prepareMultiGet()
        .add(new MultiGetRequest.Item("test", "test", "1"))
        .add(new MultiGetRequest.Item("multiIndexAlias", "test", "1"))
        .get();
    assertThat(mgetResponse.getResponses().length, is(2));

    assertThat(mgetResponse.getResponses()[0].getIndex(), is("test"));
    assertThat(mgetResponse.getResponses()[0].isFailed(), is(false));

    assertThat(mgetResponse.getResponses()[1].getIndex(), is("multiIndexAlias"));
    assertThat(mgetResponse.getResponses()[1].isFailed(), is(true));
    assertThat(mgetResponse.getResponses()[1].getFailure().getMessage(), containsString("more than one indices"));

    mgetResponse = client().prepareMultiGet()
        .add(new MultiGetRequest.Item("multiIndexAlias", "test", "1"))
        .get();
    assertThat(mgetResponse.getResponses().length, is(1));
    assertThat(mgetResponse.getResponses()[0].getIndex(), is("multiIndexAlias"));
    assertThat(mgetResponse.getResponses()[0].isFailed(), is(true));
    assertThat(mgetResponse.getResponses()[0].getFailure().getMessage(), containsString("more than one indices"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:29,代码来源:SimpleMgetIT.java


示例14: testThatParentPerDocumentIsSupported

import org.elasticsearch.action.get.MultiGetRequest; //导入依赖的package包/类
public void testThatParentPerDocumentIsSupported() throws Exception {
    assertAcked(prepareCreate("test").addAlias(new Alias("alias"))
            .addMapping("test", jsonBuilder()
                    .startObject()
                    .startObject("test")
                    .startObject("_parent")
                    .field("type", "foo")
                    .endObject()
                    .endObject()
                    .endObject()));

    client().prepareIndex("test", "test", "1").setParent("4").setRefreshPolicy(IMMEDIATE)
            .setSource(jsonBuilder().startObject().field("foo", "bar").endObject())
            .get();

    MultiGetResponse mgetResponse = client().prepareMultiGet()
            .add(new MultiGetRequest.Item(indexOrAlias(), "test", "1").parent("4"))
            .add(new MultiGetRequest.Item(indexOrAlias(), "test", "1"))
            .get();

    assertThat(mgetResponse.getResponses().length, is(2));
    assertThat(mgetResponse.getResponses()[0].isFailed(), is(false));
    assertThat(mgetResponse.getResponses()[0].getResponse().isExists(), is(true));

    assertThat(mgetResponse.getResponses()[1].isFailed(), is(true));
    assertThat(mgetResponse.getResponses()[1].getResponse(), nullValue());
    assertThat(mgetResponse.getResponses()[1].getFailure().getMessage(), equalTo("routing is required for [test]/[test]/[1]"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:29,代码来源:SimpleMgetIT.java


示例15: testThatSourceFilteringIsSupported

import org.elasticsearch.action.get.MultiGetRequest; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void testThatSourceFilteringIsSupported() throws Exception {
    assertAcked(prepareCreate("test").addAlias(new Alias("alias")));
    BytesReference sourceBytesRef = jsonBuilder().startObject()
            .array("field", "1", "2")
            .startObject("included").field("field", "should be seen").field("hidden_field", "should not be seen").endObject()
            .field("excluded", "should not be seen")
            .endObject().bytes();
    for (int i = 0; i < 100; i++) {
        client().prepareIndex("test", "type", Integer.toString(i)).setSource(sourceBytesRef, XContentType.JSON).get();
    }

    MultiGetRequestBuilder request = client().prepareMultiGet();
    for (int i = 0; i < 100; i++) {
        if (i % 2 == 0) {
            request.add(new MultiGetRequest.Item(indexOrAlias(), "type", Integer.toString(i))
                .fetchSourceContext(new FetchSourceContext(true, new String[] {"included"}, new String[] {"*.hidden_field"})));
        } else {
            request.add(new MultiGetRequest.Item(indexOrAlias(), "type", Integer.toString(i))
                .fetchSourceContext(new FetchSourceContext(false)));
        }
    }

    MultiGetResponse response = request.get();

    assertThat(response.getResponses().length, equalTo(100));
    for (int i = 0; i < 100; i++) {
        MultiGetItemResponse responseItem = response.getResponses()[i];
        assertThat(responseItem.getIndex(), equalTo("test"));
        if (i % 2 == 0) {
            Map<String, Object> source = responseItem.getResponse().getSourceAsMap();
            assertThat(source.size(), equalTo(1));
            assertThat(source, hasKey("included"));
            assertThat(((Map<String, Object>) source.get("included")).size(), equalTo(1));
            assertThat(((Map<String, Object>) source.get("included")), hasKey("field"));
        } else {
            assertThat(responseItem.getResponse().getSourceAsBytes(), nullValue());
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:41,代码来源:SimpleMgetIT.java


示例16: testThatRoutingPerDocumentIsSupported

import org.elasticsearch.action.get.MultiGetRequest; //导入依赖的package包/类
public void testThatRoutingPerDocumentIsSupported() throws Exception {
    assertAcked(prepareCreate("test").addAlias(new Alias("alias"))
            .setSettings(Settings.builder()
                    .put(indexSettings())
                    .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, between(2, DEFAULT_MAX_NUM_SHARDS))));

    final String id = routingKeyForShard("test", 0);
    final String routingOtherShard = routingKeyForShard("test", 1);

    client().prepareIndex("test", "test", id).setRefreshPolicy(IMMEDIATE).setRouting(routingOtherShard)
            .setSource(jsonBuilder().startObject().field("foo", "bar").endObject())
            .get();

    MultiGetResponse mgetResponse = client().prepareMultiGet()
            .add(new MultiGetRequest.Item(indexOrAlias(), "test", id).routing(routingOtherShard))
            .add(new MultiGetRequest.Item(indexOrAlias(), "test", id))
            .get();

    assertThat(mgetResponse.getResponses().length, is(2));
    assertThat(mgetResponse.getResponses()[0].isFailed(), is(false));
    assertThat(mgetResponse.getResponses()[0].getResponse().isExists(), is(true));
    assertThat(mgetResponse.getResponses()[0].getResponse().getIndex(), is("test"));

    assertThat(mgetResponse.getResponses()[1].isFailed(), is(false));
    assertThat(mgetResponse.getResponses()[1].getResponse().isExists(), is(false));
    assertThat(mgetResponse.getResponses()[1].getResponse().getIndex(), is("test"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:SimpleMgetIT.java


示例17: 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


示例18: 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


示例19: toMultiSearchRequest

import org.elasticsearch.action.get.MultiGetRequest; //导入依赖的package包/类
protected MultiSearchRequest toMultiSearchRequest(final RestRequest request) throws Exception {

        final MultiGetRequest multiGetRequest = new MultiGetRequest();
        multiGetRequest.refresh(request.paramAsBoolean("refresh", multiGetRequest.refresh()));
        multiGetRequest.preference(request.param("preference"));
        multiGetRequest.realtime(request.paramAsBoolean("realtime", null));
        multiGetRequest.ignoreErrorsOnGeneratedFields(request.paramAsBoolean("ignore_errors_on_generated_fields", false));

        String[] sFields = null;
        final String sField = request.param("fields");
        if (sField != null) {
            sFields = Strings.splitStringByCommaToArray(sField);
        }

        final FetchSourceContext defaultFetchSource = FetchSourceContext.parseFromRestRequest(request);
        multiGetRequest.add(request.param("index"), request.param("type"), sFields, defaultFetchSource, request.param("routing"),
                RestActions.getRestContent(request),
                settings.getAsBoolean(AbstractACRestFilter.REST_ACTION_MULTI_ALLOW_EXPLICIT_INDEX, true));

        final MultiSearchRequest msearch = new MultiSearchRequest();
        msearch.copyContextFrom(request);

        for (final Iterator<Item> iterator = multiGetRequest.iterator(); iterator.hasNext();) {
            final Item item = iterator.next();

            final SearchRequest st = new SearchRequest();
            st.routing(item.routing());
            st.indices(item.indices());
            st.types(item.type());
            st.preference(request.param("preference"));
            st.source(SearchSourceBuilder.searchSource().query(new IdsQueryBuilder(item.type()).addIds(item.id())));
            msearch.add(st);
        }

        return msearch;

    }
 
开发者ID:petalmd,项目名称:armor,代码行数:38,代码来源:AbstractACRestFilter.java


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TransitRouteLine类代码示例发布时间:2022-05-22
下一篇:
Java SecondaryIndexSearcher类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap