Package org.elasticsearch.action.get

Examples of org.elasticsearch.action.get.MultiGetRequestBuilder


    List<P> list = new ArrayList<P>();
    if (ids == null || ids.isEmpty()) {
      return list;
    }
    try {
      MultiGetRequestBuilder mgr = client().prepareMultiGet();
      for (String id : ids) {
        MultiGetRequest.Item i = new MultiGetRequest.Item(stripRouting(appid), null, id);
        i.routing(getRouting(appid, id));
        mgr.add(i);
      }

      MultiGetResponse response = mgr.execute().actionGet();
      for (MultiGetItemResponse multiGetItemResponse : response.getResponses()) {
        GetResponse res = multiGetItemResponse.getResponse();
        if (res.isExists() && !res.isSourceEmpty()) {
          list.add((P) Utils.setAnnotatedFields(res.getSource()));
        }
View Full Code Here


        if (resolveConflicts) {
            String index = getElasticSearchIndexNameFromDatabase(database);
            // the following debug code is verbose in the hopes of better understanding CBES-13
            MultiGetResponse response = null;
            if(client != null) {
                MultiGetRequestBuilder builder = client.prepareMultiGet();
                if(builder != null) {
                    if(index == null) {
                        logger.debug("index is null");
                    }
                    int added = 0;
                    for (String id : responseMap.keySet()) {
                        String type = typeSelector.getType(index, id);
                        if(documentTypeRoutingFields != null && documentTypeRoutingFields.containsKey(type)) {
                            // if this type requires special routing, we can't find it without the doc body
                            // so we skip this id in the lookup to avoid errors
                            continue;
                        }
                        builder = builder.add(index, type, id);
                        added++;
                    }
                    if(builder != null) {
                        if(added > 0) {
                            ListenableActionFuture<MultiGetResponse> laf = builder.execute();
                            if(laf != null) {
                                response = laf.actionGet();
                            } else {
                                logger.debug("laf was null");
                            }
View Full Code Here

    List<P> list = new ArrayList<P>();
    if (ids == null || ids.isEmpty()) {
      return list;
    }
    try {
      MultiGetRequestBuilder mgr = client().prepareMultiGet();
      for (String id : ids) {
        MultiGetRequest.Item i = new MultiGetRequest.Item(stripRouting(appid), null, id);
        i.routing(getRouting(appid, id));
        mgr.add(i);
      }

      MultiGetResponse response = mgr.execute().actionGet();
      for (MultiGetItemResponse multiGetItemResponse : response.getResponses()) {
        GetResponse res = multiGetItemResponse.getResponse();
        if (res.isExists() && !res.isSourceEmpty()) {
          list.add(Utils.setAnnotatedFields(res.getSource()));
        }
View Full Code Here

    @Override
    public ListenableActionFuture<MultiGetResponse> execute(Client client, String indexName, OperationContext helper) {
      final TypeMapping typeMapping = helper.findTypeMapping(_type);
      final String type = typeMapping.getTypeAlias();

      MultiGetRequestBuilder builder = client.prepareMultiGet();
      for (Object id : _ids) {
        // ignore indexName as it may be a multi-index
        builder.add(helper.findIndexName(_type), type, typeMapping.toIdString(id));
      }

      return builder.execute();
    }
View Full Code Here

    Assert.notNull(indexName, "No index defined for Query");
    Assert.notNull(type, "No type define for Query");
    Assert.notEmpty(searchQuery.getIds(), "No Id define for Query");

    MultiGetRequestBuilder builder = client.prepareMultiGet();

    for (String id : searchQuery.getIds()) {

      MultiGetRequest.Item item = new MultiGetRequest.Item(indexName, type, id);

      if (searchQuery.getRoute() != null) {
        item = item.routing(searchQuery.getRoute());
      }

      if (searchQuery.getFields() != null && !searchQuery.getFields().isEmpty()) {
        item = item.fields(toArray(searchQuery.getFields()));
      }
      builder.add(item);
    }
    return builder.execute().actionGet();
  }
View Full Code Here

  SearchClient searchClient = new SearchClient(new Settings(), profiling);

  @Test
  public void multi_get() {
    try {
      MultiGetRequestBuilder request = searchClient.prepareMultiGet();
      request.add(new MultiGetRequest.Item(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexType(), "ruleKey")
        .fetchSourceContext(FetchSourceContext.FETCH_SOURCE));
      request.get();

      // expected to fail because elasticsearch is not correctly configured, but that does not matter
      fail();
    } catch (Exception e) {
      assertThat(e).isInstanceOf(IllegalStateException.class);
View Full Code Here

  public void with_profiling_basic() {
    Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.BASIC.name()));
    SearchClient searchClient = new SearchClient(new Settings(), profiling);

    try {
      MultiGetRequestBuilder request = searchClient.prepareMultiGet();
      request.add(new MultiGetRequest.Item(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexType(), "ruleKey")
        .fetchSourceContext(FetchSourceContext.FETCH_SOURCE));
      request.get();

      // expected to fail because elasticsearch is not correctly configured, but that does not matter
      fail();
    } catch (Exception e) {
      assertThat(e).isInstanceOf(IllegalStateException.class);
View Full Code Here

  @Test
  public void getNodeItems() {
    // Setup
    Way way = OsmDataBuilder.buildSampleWay();

    MultiGetRequestBuilder multiGetRequestBuilderMocked = mock(MultiGetRequestBuilder.class);
    when(clientMocked.prepareMultiGet()).thenReturn(multiGetRequestBuilderMocked);

    ListenableActionFuture<MultiGetResponse> listenableActionFutureMocked = mock(ListenableActionFuture.class);
    when(multiGetRequestBuilderMocked.execute()).thenReturn(listenableActionFutureMocked);
    MultiGetResponse multiGetResponseMocked = mock(MultiGetResponse.class);
    when(listenableActionFutureMocked.actionGet()).thenReturn(multiGetResponseMocked);
    Iterator<MultiGetItemResponse> iteratorMocked = mock(Iterator.class);
    when(multiGetResponseMocked.iterator()).thenReturn(iteratorMocked);
View Full Code Here

  public void findAll() {
    // Setup
    Node node1 = OsmDataBuilder.buildSampleNode(1);
    Node node2 = OsmDataBuilder.buildSampleNode(2);

    MultiGetRequestBuilder multiGetRequestBuilderMocked = mock(MultiGetRequestBuilder.class);
    doReturn(multiGetRequestBuilderMocked).when(entityDao).buildMultiGetRequest(ESNode.class, 1, 2);
    doReturn(Arrays.asList(node1, node2)).when(entityDao).executeMultiGetRequest(ESNode.class, multiGetRequestBuilderMocked);

    // Action
    List<ESNode> nodes = entityDao.findAll(ESNode.class, 1, 2);
View Full Code Here

  }

  @Test(expected = DaoException.class)
  public void findAll_withException() {
    // Setup
    MultiGetRequestBuilder multiGetRequestBuilderMocked = mock(MultiGetRequestBuilder.class);
    doReturn(multiGetRequestBuilderMocked).when(entityDao).buildMultiGetRequest(ESNode.class, 1, 2);
    doThrow(new RuntimeException("Simulated Exception")).when(entityDao).executeMultiGetRequest(ESNode.class, multiGetRequestBuilderMocked);

    // Action
    entityDao.findAll(ESNode.class, 1, 2);
View Full Code Here

TOP

Related Classes of org.elasticsearch.action.get.MultiGetRequestBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.