private void removeIndices(IndicesAdminClient indices) {
   DeleteIndexRequestBuilder chatsDeleteBuilder =
       new DeleteIndexRequestBuilder(indices, DeleteIndexAction.INSTANCE, "chats");
   DeleteIndexRequestBuilder channelsDeleteBuilder =
       new DeleteIndexRequestBuilder(indices, DeleteIndexAction.INSTANCE, "channels");
   indices.delete(chatsDeleteBuilder.request());
   indices.delete(channelsDeleteBuilder.request());
 }
 private void createChatsIndex(IndicesAdminClient indices) {
   CreateIndexRequest createBuilder = new CreateIndexRequest("chats");
   try {
     // @formatter:off
     XContentBuilder mappingBuilder =
         XContentFactory.jsonBuilder()
             .startObject()
             .startObject("chat")
             .startObject("properties")
             .startObject("date")
             .field("type", "long")
             .endObject()
             .startObject("type")
             .field("type", "string")
             .field("index", "not_analyzed")
             .endObject()
             .endObject()
             .endObject()
             .endObject();
     createBuilder.mapping("chat", mappingBuilder);
     // @formatter:on
   } catch (IOException e) {
     e.printStackTrace();
   }
   indices.create(createBuilder);
 }
Beispiel #3
0
 @NotNull
 protected IndexMetaData createIndex() {
   IndicesAdminClient idxAdmin = opalSearchService.getClient().admin().indices();
   if (!idxAdmin.exists(new IndicesExistsRequest(getName())).actionGet().isExists()) {
     log.info("Creating index [{}]", getName());
     idxAdmin.prepareCreate(getName()).setSettings(getIndexSettings()).execute().actionGet();
   }
   return opalSearchService
       .getClient()
       .admin()
       .cluster()
       .prepareState()
       .setIndices(getName())
       .execute()
       .actionGet()
       .getState()
       .getMetaData()
       .index(getName());
 }
Beispiel #4
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;
  }
 private void createChannelsIndex(IndicesAdminClient indices) {
   CreateIndexRequest createBuilder = new CreateIndexRequest("channels");
   try {
     // @formatter:off
     XContentBuilder mappingBuilder =
         XContentFactory.jsonBuilder()
             .startObject()
             .startObject("channel")
             .startObject("properties")
             .startObject("topic")
             .field("type", "object") // we only have one so don't use type 'nested'
             .endObject()
             .startObject("topic.time")
             .field("type", "long")
             .endObject()
             .startObject("last_activity")
             .field("type", "long")
             .endObject()
             .startObject("added_at")
             .field("type", "long")
             .endObject()
             .startObject("last_activity_valid") // was last_valid_content_at
             .field("type", "long")
             .endObject()
             .startObject("_name_suggest")
             .field("payloads", true)
             .field("index_analyzer", "simple")
             .field("search_analyzer", "simple")
             .field("type", "completion")
             .endObject()
             .endObject()
             .endObject()
             .endObject();
     createBuilder.mapping("channel", mappingBuilder);
     // @formatter:on
   } catch (IOException e) {
     e.printStackTrace();
   }
   indices.create(createBuilder);
 }
 @Override
 protected void doExecute(ActionListener<GetFieldMappingsResponse> listener) {
   ((IndicesAdminClient) client).getFieldMappings(request, listener);
 }
 @Override
 protected void doExecute(ActionListener<IndicesSegmentResponse> listener) {
   ((IndicesAdminClient) client).segments(request, listener);
 }
 @Override
 protected void doExecute(ActionListener<IndicesAliasesResponse> listener) {
   ((IndicesAdminClient) client).aliases(request, listener);
 }