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


Java MultiGetRequest类代码示例

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


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


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