Package org.elasticsearch.action.admin.indices.create

Examples of org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder


          "german", "greek", "hindi", "hungarian", "indonesian", "italian",
          "norwegian", "persian", "portuguese", "romanian", "russian", "spanish",
          "swedish", "turkish");

      String name = appid + "1";
      CreateIndexRequestBuilder create = getClient().admin().indices().prepareCreate(name).
          setSettings(nb.settings().build());

      // default system mapping (all the rest are dynamic)
      create.addMapping("_default_", getDefaultMapping());
      create.execute().actionGet();

      addIndexAlias(name, appid);
    } catch (Exception e) {
      logger.warn(null, e);
      return false;
View Full Code Here


     * Create the index
     */
    public static void createIndex(String indexName) {
        Logger.debug("ElasticSearch : creating index [" + indexName + "]");
        try {
            CreateIndexRequestBuilder creator = IndexClient.client.admin().indices().prepareCreate(indexName);
            String setting = IndexClient.config.indexSettings.get(indexName);
            if (setting != null) {
                creator.setSettings(setting);
            }
            creator.execute().actionGet();
        } catch (Exception e) {
            Logger.error("ElasticSearch : Index create error : " + e.toString());
        }
    }
View Full Code Here

          "german", "greek", "hindi", "hungarian", "indonesian", "italian",
          "norwegian", "persian", "portuguese", "romanian", "russian", "spanish",
          "swedish", "turkish");

      String name = appid + "1";
      CreateIndexRequestBuilder create = getClient().admin().indices().prepareCreate(name).
          setSettings(nb.settings().build());

      // default system mapping (all the rest are dynamic)
      create.addMapping("_default_", getDefaultMapping());
      create.execute().actionGet();

      getClient().admin().indices().prepareAliases().addAlias(name, appid).execute().actionGet();
    } catch (Exception e) {
      logger.warn(null, e);
      return false;
View Full Code Here

    IndicesExistsResponse existsResponse = _client.getClient().admin().indices().prepareExists(_indexName)
        .execute().actionGet();

    if (!existsResponse.isExists()) {
      // create index
      CreateIndexRequestBuilder request = _client.getClient().admin().indices().prepareCreate(_indexName);

      Settings settings = getStoreSettings(index);
      if (settings != null) {
        request.setSettings(settings);
      }

      CreateIndexResponse response = request
          .setTimeout(TimeValue.timeValueSeconds(INDEX_CREATION_TIMEOUT_SECONDS)).execute().actionGet();

      if (!response.isAcknowledged()) {
        log.warn("index creation not acknowledged within " + INDEX_CREATION_TIMEOUT_SECONDS + " seconds");
      }
View Full Code Here

    return createIndex(getPersistentEntityFor(clazz).getIndexName(), getDefaultSettings(getPersistentEntityFor(clazz)));
  }

  @Override
  public boolean createIndex(String indexName, Object settings) {
    CreateIndexRequestBuilder createIndexRequestBuilder = client.admin().indices().prepareCreate(indexName);
    if (settings instanceof String) {
      createIndexRequestBuilder.setSettings(String.valueOf(settings));
    } else if (settings instanceof Map) {
      createIndexRequestBuilder.setSettings((Map) settings);
    } else if (settings instanceof XContentBuilder) {
      createIndexRequestBuilder.setSettings((XContentBuilder) settings);
    }
    return createIndexRequestBuilder.execute().actionGet().isAcknowledged();
  }
View Full Code Here

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

  @Test
  public void create_index() {
    try {
      CreateIndexRequestBuilder requestBuilder = searchClient.prepareCreate("new");
      requestBuilder.get();

      // expected to fail because elasticsearch is not correctly configured, but that does not matter
      fail();
    } catch (IllegalStateException e) {
      assertThat(e.getMessage()).isEqualTo("Fail to execute ES create index 'new'");
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 {
      CreateIndexRequestBuilder requestBuilder = searchClient.prepareCreate("new");
      requestBuilder.get();

      // expected to fail because elasticsearch is not correctly configured, but that does not matter
      fail();
    } catch (IllegalStateException e) {
      assertThat(e.getMessage()).isEqualTo("Fail to execute ES create index 'new'");
View Full Code Here

          "german", "greek", "hindi", "hungarian", "indonesian", "italian",
          "norwegian", "persian", "portuguese", "romanian", "russian", "spanish",
          "swedish", "turkish");

      String name = appid + "1";
      CreateIndexRequestBuilder create = getClient().admin().indices().prepareCreate(name).
          setSettings(nb.settings().build());

      // default system mapping (all the rest are dynamic)
      create.addMapping("_default_", getDefaultMapping());
      create.execute().actionGet();

      getClient().admin().indices().prepareAliases().addAlias(name, appid).execute().actionGet();
    } catch (Exception e) {
      logger.warn(null, e);
      return false;
View Full Code Here

     * @return {@code true} if an error occurs during the creation.
     */
    private boolean createIndex() {
        for (String type : TYPES) {
            try {
                CreateIndexRequestBuilder createIndex = client().admin().indices().prepareCreate(indexName(type));
                URL mappingUrl = getClass().getClassLoader().getResource("META-INF/elasticsearch/index/" + type + ".json");

                ObjectMapper jsonMapper = new ObjectMapper();
                JsonNode indexConfig = jsonMapper.readTree(mappingUrl);
                JsonNode indexSettings = indexConfig.get("settings");
                if (indexSettings != null && indexSettings.isObject()) {
                    createIndex.setSettings(jsonMapper.writeValueAsString(indexSettings));
                }

                JsonNode mappings = indexConfig.get("mappings");
                if (mappings != null && mappings.isObject()) {
                    for (Iterator<Map.Entry<String, JsonNode>> i = mappings.fields(); i.hasNext(); ) {
                        Map.Entry<String, JsonNode> field = i.next();
                        ObjectNode mapping = jsonMapper.createObjectNode();
                        mapping.put(field.getKey(), field.getValue());
                        createIndex.addMapping(field.getKey(), jsonMapper.writeValueAsString(mapping));
                    }
                }

                boolean ack = createIndex.execute().actionGet().acknowledged();
                if (!ack) {
                    log.error("Cannot create index " + indexName(type));
                    return false;
                }

View Full Code Here

          "german", "greek", "hindi", "hungarian", "indonesian", "italian",
          "norwegian", "persian", "portuguese", "romanian", "russian", "spanish",
          "swedish", "turkish");

      String name = appid + "1";
      CreateIndexRequestBuilder create = getClient().admin().indices().prepareCreate(name).
          setSettings(nb.settings().build());

      // default system mapping (all the rest are dynamic)
      create.addMapping("_default_", getDefaultMapping());
      create.execute().actionGet();

      addIndexAlias(name, appid);
    } catch (Exception e) {
      logger.warn(null, e);
      return false;
View Full Code Here

TOP

Related Classes of org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder

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.