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

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


    if (logger.isTraceEnabled()) logger.trace("createIndex("+index+")");
    if (logger.isDebugEnabled()) logger.debug("Index " + index + " doesn't exist. Creating it.");
   
    checkClient();
   
    CreateIndexRequestBuilder cirb = client.admin().indices().prepareCreate(index);

    // If there are settings for this index, we use it. If not, using Elasticsearch defaults.
    String source = readIndexSettings(index);
    if (source != null) {
      if (logger.isTraceEnabled()) logger.trace("Found settings for index "+index+" : " + source);
      cirb.setSettings(source);
    }
   
    CreateIndexResponse createIndexResponse = cirb.execute().actionGet();
    if (!createIndexResponse.isAcknowledged()) throw new Exception("Could not create index ["+index+"].");
    if (logger.isTraceEnabled()) logger.trace("/createIndex("+index+")");
  }
View Full Code Here


        execute(CreateIndexAction.INSTANCE, request, listener);
    }

    @Override
    public CreateIndexRequestBuilder prepareCreate(String index) {
        return new CreateIndexRequestBuilder(this, index);
    }
View Full Code Here

    }

    @Test
    public void testCreateIndexWithAliasesFilterNotValid() {
        //non valid filter, invalid json
        CreateIndexRequestBuilder createIndexRequestBuilder = prepareCreate("test").addAlias(new Alias("alias2").filter("f"));

        try {
            createIndexRequestBuilder.get();
            fail("create index should have failed due to invalid alias filter");
        } catch (ElasticsearchIllegalArgumentException e) {
            assertThat(e.getMessage(), equalTo("failed to parse filter for alias [alias2]"));
        }

        //valid json but non valid filter
        createIndexRequestBuilder = prepareCreate("test").addAlias(new Alias("alias2").filter("{ \"test\": {} }"));

        try {
            createIndexRequestBuilder.get();
            fail("create index should have failed due to invalid alias filter");
        } catch (ElasticsearchIllegalArgumentException e) {
            assertThat(e.getMessage(), equalTo("failed to parse filter for alias [alias2]"));
        }
    }
View Full Code Here

        return 0;
    }

    @Test
    public void testRegexpFilter() throws IOException {
        CreateIndexRequestBuilder builder = prepareCreate("test");
        XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
                .startObject("properties")
                    .startObject("name")
                        .field("type", "string")
                        .startObject("fielddata")
                            .startObject("filter")
                                .startObject("regex")
                                    .field("pattern", "^bac.*")
                                .endObject()
                            .endObject()
                        .endObject()
                    .endObject()
                    .startObject("not_filtered")
                        .field("type", "string")
                    .endObject()
                .endObject()
                .endObject().endObject();
        assertAcked(builder.addMapping("type", mapping));
        ensureGreen();
        int numDocs = scaledRandomIntBetween(5, 50);
        for (int i = 0; i < numDocs; i++) {
            client().prepareIndex("test", "type", "" + 0).setSource("name", "bacon bastards", "not_filtered", "bacon bastards").get();
        }
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

     * 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

      IOException {

    // Make sure the site index exists
    try {
      IndicesAdminClient indexAdmin = nodeClient.admin().indices();
      CreateIndexRequestBuilder siteIdxRequest = indexAdmin.prepareCreate(site.getIdentifier());
      logger.debug("Trying to create site index for '{}'", site.getIdentifier());
      CreateIndexResponse siteidxResponse = siteIdxRequest.execute().actionGet();
      if (!siteidxResponse.acknowledged()) {
        throw new ContentRepositoryException("Unable to create site index for '" + site.getIdentifier() + "'");
      }
    } catch (IndexAlreadyExistsException e) {
      logger.info("Detected existing index '{}'", site.getIdentifier());
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.