private void updateMappings() {
    for (String entity : mappingGenerators.keySet()) {
      EntityMappingGenerator generator = mappingGenerators.get(entity);
      Map<String, Object> mapping = generator.generateMapping();
      if (mapping != null) {
        final String type = generator.forClass().getSimpleName().toLowerCase();
        ListenableActionFuture<PutMappingResponse> future =
            client
                .admin()
                .indices()
                .preparePutMapping("entities")
                .setType(type)
                .setSource(mapping)
                .execute();

        future.addListener(
            new ActionListener<PutMappingResponse>() {
              public void onResponse(PutMappingResponse putMappingResponse) {
                logger.info("Mapping for entity [{}] updated", type);
              }

              public void onFailure(Throwable throwable) {
                logger.error("Error updating mapping for entity {}", type, throwable);
              }
            });

        future.actionGet();
      }
    }
  }
Beispiel #2
0
  @Test
  public void testGetSlash() {
    final String id = "get-test/id-2";
    final IndexRequestBuilder indexRequestBuilder =
        restClient().prepareIndex(index, type, id).setSource("field", "value").setRefresh(true);
    indexRequestBuilder.execute().actionGet();

    final GetRequestBuilder getRequestBuilder = restClient().prepareGet(index, type, id);
    final ListenableActionFuture<GetResponse> execute1 = getRequestBuilder.execute();
    final GetResponse get = execute1.actionGet();
    assertEquals(get.getIndex(), index);
    assertEquals(get.getType(), type);
    assertEquals(get.getId(), id);
    assertEquals(get.getVersion(), 1);
    assertTrue(get.getFields().isEmpty());
    assertEquals(get.getSource().get("field"), "value");
  }
Beispiel #3
0
  public AsyncFuture<Void> configure() {
    final IndicesAdminClient indices = client.admin().indices();

    log.info("[{}] updating template for {}", templateName, index.template());

    final PutIndexTemplateRequestBuilder put = indices.preparePutTemplate(templateName);

    put.setSettings(settings);
    put.setTemplate(index.template());

    for (final Map.Entry<String, Map<String, Object>> mapping : mappings.entrySet()) {
      put.addMapping(mapping.getKey(), mapping.getValue());
    }

    final ResolvableFuture<Void> future = async.future();

    final ListenableActionFuture<PutIndexTemplateResponse> target = put.execute();

    target.addListener(
        new ActionListener<PutIndexTemplateResponse>() {
          @Override
          public void onResponse(final PutIndexTemplateResponse response) {
            if (!response.isAcknowledged()) {
              future.fail(new Exception("request not acknowledged"));
              return;
            }

            future.resolve(null);
          }

          @Override
          public void onFailure(Throwable e) {
            future.fail(e);
          }
        });

    future.onCancelled(() -> target.cancel(false));
    return future;
  }