/** * If ES already contains this instance's target index, then do nothing. * Otherwise, create the index, then wait {@link #CREATE_SLEEP}. * <p> * The {@code client} field must point to a live, connected client. * The {@code indexName} field must be non-null and point to the name * of the index to check for existence or create. * * @param config the config for this ElasticSearchIndex * @throws java.lang.IllegalArgumentException if the index could not be created */ private void checkForOrCreateIndex(Configuration config) { Preconditions.checkState(null != client); //Create index if it does not already exist IndicesExistsResponse response = client.admin().indices().exists(new IndicesExistsRequest(indexName)).actionGet(); if (!response.isExists()) { ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder(); ElasticSearchSetup.applySettingsFromTitanConf(settings, config, ES_CREATE_EXTRAS_NS); CreateIndexResponse create = client.admin().indices().prepareCreate(indexName) .setSettings(settings.build()).execute().actionGet(); try { final long sleep = config.get(CREATE_SLEEP); log.debug("Sleeping {} ms after {} index creation returned from actionGet()", sleep, indexName); Thread.sleep(sleep); } catch (InterruptedException e) { throw new TitanException("Interrupted while waiting for index to settle in", e); } if (!create.isAcknowledged()) throw new IllegalArgumentException("Could not create index: " + indexName); } }
@Override protected CreateIndexResponse newResponse() { return new CreateIndexResponse(); }
/** * Returns true if the requisite number of shards were started before * returning from the index creation operation. If {@link #isAcknowledged()} * is false, then this also returns false. * * @deprecated use {@link #isShardsAcknowledged()} */ @Deprecated public boolean isShardsAcked() { return isShardsAcknowledged(); }
Assert.assertEquals(clusterInfo.numNodes, tc.admin().cluster().nodesInfo(new NodesInfoRequest()).actionGet().getNodes().size()); CreateIndexResponse cir = tc.admin().indices().create(new CreateIndexRequest("vulcan")).actionGet(); Assert.assertTrue(cir.isAcknowledged());
CreateIndexResponse indexResponse = SHARED_NODE.client().admin().indices() .prepareCreate(index.getName()) .setSettings(settings) .get(); if (!indexResponse.isAcknowledged()) { throw new IllegalStateException("Failed to create index " + index.getName()); SHARED_NODE.client().admin().cluster().prepareHealth(index.getName()).setWaitForStatus(ClusterHealthStatus.YELLOW).get(); PutMappingResponse mappingResponse = SHARED_NODE.client().admin().indices().preparePutMapping(index.getName()) .setType(entry.getKey()) .setSource(entry.getValue().getAttributes())
IndicesExistsResponse response = client.admin().indices() .exists(new IndicesExistsRequest(indexName)).actionGet(); client.admin().indices().prepareDelete(this.indexName).execute() .actionGet(); forceCreate = true; CreateIndexResponse create = client.admin().indices() .prepareCreate(indexName).execute().actionGet(); try { Thread.sleep(200); "Interrupted while waiting for index to settle in", e); if (!create.isAcknowledged()) { throw new IllegalArgumentException("Could not create index: " + indexName);
log.debug("Configured ES query result set max size to {}", maxResultsSize); client.admin().cluster().prepareHealth() .setWaitForYellowStatus().execute().actionGet(); IndicesExistsResponse response = client.admin().indices().exists(new IndicesExistsRequest(indexName)).actionGet(); if (!response.isExists()) { CreateIndexResponse create = client.admin().indices().prepareCreate(indexName).execute().actionGet(); try { Thread.sleep(200); throw new TitanException("Interrupted while waiting for index to settle in", e); if (!create.isAcknowledged()) throw new IllegalArgumentException("Could not create index: " + indexName);
public void open() { final IndicesExistsResponse existsResponse = client.admin().indices() .prepareExists(index).execute().actionGet(); if (!existsResponse.isExists()) { final CreateIndexResponse createIndexResponse = client.admin() .indices().prepareCreate(index).execute().actionGet(); if (!createIndexResponse.isAcknowledged()) { throw new TasteException("Failed to create " + index + " index."); } } if (mappingBuilder != null) { final GetMappingsResponse response = client.admin().indices() .prepareGetMappings(index).setTypes(type).execute() .actionGet(); if (response.mappings().isEmpty()) { final PutMappingResponse putMappingResponse = client.admin() .indices().preparePutMapping(index).setType(type) .setSource(mappingBuilder).execute().actionGet(); if (!putMappingResponse.isAcknowledged()) { throw new TasteException("Failed to create a mapping of" + index + "/" + type); } } } }
if (!client.admin().indices().prepareExists(index).execute().actionGet().isExists()) { final CreateIndexRequestBuilder createIndexRequestBuilder = client.admin().indices().prepareCreate(index); if (settings != null) { logger.debug("index settings are provided, will apply them {}", settings); createIndexRequestBuilder.setSettings(settings); } else { logger.debug("no settings given for index '{}'",index); createIndexRequestBuilder.addMapping(type, mapping); } else { logger.debug("no mapping given for type '{}', will apply default mapping",type); createIndexRequestBuilder.addMapping(type, getDefaultTypeMapping()); final CreateIndexResponse res = createIndexRequestBuilder.get(); if (!res.isAcknowledged()) { throw new IOException("Could not create index " + index);
boolean indexExists = client.admin().indices().exists(new IndicesExistsRequest(index)).actionGet().isExists(); if(!indexExists){ CreateIndexResponse response = client.admin().indices().prepareCreate(index).addMapping(type, json, XContentType.JSON).get(); if(!response.isAcknowledged()) throw new SQLException("Table creation failed because database '"+index+"' could not be created"); }else{ PutMappingResponse response = client.admin().indices().preparePutMapping(index).setType(type).setSource(json, XContentType.JSON).get(); if(!response.isAcknowledged()) throw new SQLException("Table creation failed due to unknown reason");
IndicesExistsResponse indicesExistsResponse = nodeClient.admin().indices() .exists(new IndicesExistsRequest(idx)).actionGet(); if (!indicesExistsResponse.isExists()) { logger.debug("Trying to create index for '{}'", idx); if (settings != null) indexCreateRequest.settings(settings); CreateIndexResponse siteidxResponse = nodeClient.admin().indices().create(indexCreateRequest).actionGet(); if (!siteidxResponse.isAcknowledged()) { throw new SearchIndexException("Unable to create index for '" + idx + "'"); siteMappingRequest.source(getIndexTypeDefinition(idx, type)); siteMappingRequest.type(type); PutMappingResponse siteMappingResponse = nodeClient.admin().indices().putMapping(siteMappingRequest).actionGet(); if (!siteMappingResponse.isAcknowledged()) { throw new SearchIndexException("Unable to install '" + type + "' mapping for index '" + idx + "'");
Settings indexSettings = Settings.builder().put("index.number_of_replicas", updateSettings).build(); tc.execute(ConfigUpdateAction.INSTANCE, new ConfigUpdateRequest(new String[]{"config","roles","rolesmapping","internalusers","actiongroups"})).actionGet(); final AcknowledgedResponse response = tc.admin().indices().updateSettings((new UpdateSettingsRequest(index).settings(indexSettings))).actionGet(); System.out.println("Reload config on all nodes"); System.out.println("Update number of replicas to "+(updateSettings) +" with result: "+response.isAcknowledged()); .build(); tc.execute(ConfigUpdateAction.INSTANCE, new ConfigUpdateRequest(new String[]{"config","roles","rolesmapping","internalusers","actiongroups"})).actionGet(); final AcknowledgedResponse response = tc.admin().indices().updateSettings((new UpdateSettingsRequest(index).settings(indexSettings))).actionGet(); System.out.println("Reload config on all nodes"); System.out.println("Auto-expand replicas "+(replicaAutoExpand?"enabled":"disabled")); final boolean successful = tc.admin().cluster() .updateSettings(new ClusterUpdateSettingsRequest() .transientSettings(ENABLE_ALL_ALLOCATIONS_SETTINGS) sgIndex = tc.admin().indices().getIndex(new GetIndexRequest().indices(index).addFeatures(Feature.MAPPINGS)).actionGet(); } catch (IndexNotFoundException e1) { final boolean indexCreated = tc.admin().indices().create(new CreateIndexRequest(index) .settings(indexSettings)) .actionGet().isAcknowledged();
public void createIndexWithMapping(String indexName, String mappingType, String mappingSource) throws IOException { CreateIndexResponse cir = client.admin().indices().prepareCreate(indexName) .addMapping(mappingType, mappingSource) .get(); if (!cir.isAcknowledged()) { throw new IOException("Create index was not acknowledged"); } }
@VisibleForTesting protected String createIndex() { final String indexName = this.configuration.getAlias() + "_" + System.currentTimeMillis(); CreateIndexRequestBuilder prepareCreate = this.client.admin().indices() .prepareCreate(indexName); if (this.configuration.getSource() != null) { try { prepareCreate .setSource(ByteStreams.toByteArray(this.configuration.getSource().getInputStream())); } catch (IOException e) { logger.error("Can't read index {} configuration file {}", indexName, this.configuration.getSource(), e); } } CreateIndexResponse createIndexResponse = prepareCreate.get(); if (!createIndexResponse.isAcknowledged()) { throw new IllegalStateException("Error creating index for Lotus BO"); } return indexName; }
public static void createIndexELServer( String index, String jsonMappingsFile ) throws Exception { // Obtain data to configure & populate the server. String mappingsContent = getFileAsString(jsonMappingsFile); CreateIndexRequest indexRequest = new CreateIndexRequestBuilder( client, CreateIndexAction.INSTANCE ) .setIndex( index) .setSource( mappingsContent ) .request(); CreateIndexResponse indexResponse = client.admin().indices().create( indexRequest ).actionGet(); if ( !indexResponse.isAcknowledged() ) { throw new RuntimeException( "Error creating index [" + index + "]" ); } }
/** * createIndexIfMissing. * @param indexName indexName */ public void createIndexIfMissing(String indexName) { if (!this.manager.client() .admin() .indices() .exists(new IndicesExistsRequest(indexName)) .actionGet() .isExists()) { // It does not exist... So we are going to need to create the index. // we are going to assume that the 'templates' that we have loaded into // elasticsearch are sufficient to ensure the index is being created properly. CreateIndexResponse response = this.manager.client().admin().indices().create(new CreateIndexRequest(indexName)).actionGet(); if (response.isAcknowledged()) { LOGGER.info("Index {} did not exist. The index was automatically created from the stored ElasticSearch Templates.", indexName); } else { LOGGER.error("Index {} did not exist. While attempting to create the index from stored ElasticSearch Templates we were unable to get an acknowledgement.", indexName); LOGGER.error("Error Message: {}", response.toString()); throw new RuntimeException("Unable to create index " + indexName); } } }
.setSettings(settings) .get(); if (!indexResponse.isAcknowledged()) { throw new IllegalStateException("Failed to create index " + index.getName());
@Override public boolean createIndex(String indexName) { Assert.notNull(indexName, "No index defined for Query"); try { return client.indices().create(Requests.createIndexRequest(indexName)).isAcknowledged(); } catch (Exception e) { throw new ElasticsearchException("Failed to create index " + indexName, e); } }
@Override public boolean createIndex(String indexName) { Assert.notNull(indexName, "No index defined for Query"); return getIndicesAdminClient().create(Requests.createIndexRequest(indexName)).actionGet().isAcknowledged(); }
/** * Assert that an index creation was fully acknowledged, meaning that both the index creation cluster * state update was successful and that the requisite number of shard copies were started before returning. */ public static void assertAcked(CreateIndexResponse response) { assertThat(response.getClass().getSimpleName() + " failed - not acked", response.isAcknowledged(), equalTo(true)); assertVersionSerializable(response); assertTrue(response.getClass().getSimpleName() + " failed - index creation acked but not all shards were started", response.isShardsAcknowledged()); }