org.elasticsearch.action.admin.indices.create.CreateIndexResponse Java Examples
The following examples show how to use
org.elasticsearch.action.admin.indices.create.CreateIndexResponse.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SetupDao.java From usergrid with Apache License 2.0 | 7 votes |
public void setup() throws IOException, NoSuchFieldException, IllegalAccessException { String key; CreateIndexResponse ciResp; Reflections reflections = new Reflections("org.apache.usergrid.chop.webapp.dao"); Set<Class<? extends Dao>> daoClasses = reflections.getSubTypesOf(Dao.class); IndicesAdminClient client = elasticSearchClient.getClient().admin().indices(); for (Class<? extends Dao> daoClass : daoClasses) { key = daoClass.getDeclaredField("DAO_INDEX_KEY").get(null).toString(); if (!client.exists(new IndicesExistsRequest(key)).actionGet().isExists()) { ciResp = client.create(new CreateIndexRequest(key)).actionGet(); if (ciResp.isAcknowledged()) { LOG.debug("Index for key {} didn't exist, now created", key); } else { LOG.debug("Could not create index for key: {}", key); } } else { LOG.debug("Key {} already exists", key); } } }
Example #2
Source File: IndexServiceImpl.java From microservices-platform with Apache License 2.0 | 6 votes |
@Override public boolean create(IndexDto indexDto) throws IOException { CreateIndexRequest request = new CreateIndexRequest(indexDto.getIndexName()); request.settings(Settings.builder() .put("index.number_of_shards", indexDto.getNumberOfShards()) .put("index.number_of_replicas", indexDto.getNumberOfReplicas()) ); if (StrUtil.isNotEmpty(indexDto.getType()) && StrUtil.isNotEmpty(indexDto.getMappingsSource())) { //mappings request.mapping(indexDto.getType(), indexDto.getMappingsSource(), XContentType.JSON); } CreateIndexResponse response = elasticsearchRestTemplate.getClient() .indices() .create(request, RequestOptions.DEFAULT); return response.isAcknowledged(); }
Example #3
Source File: InternalEsClient.java From io with Apache License 2.0 | 6 votes |
/** * インデックスを作成する. * @param index インデックス名 * @param mappings マッピング情報 * @return 非同期応答 */ public ActionFuture<CreateIndexResponse> createIndex(String index, Map<String, JSONObject> mappings) { this.fireEvent(Event.creatingIndex, index); CreateIndexRequestBuilder cirb = new CreateIndexRequestBuilder(esTransportClient.admin().indices(), CreateIndexAction.INSTANCE, index); // cjkアナライザ設定 Settings.Builder indexSettings = Settings.settingsBuilder(); indexSettings.put("analysis.analyzer.default.type", "cjk"); cirb.setSettings(indexSettings); if (mappings != null) { for (Map.Entry<String, JSONObject> ent : mappings.entrySet()) { cirb = cirb.addMapping(ent.getKey(), ent.getValue().toString()); } } return cirb.execute(); }
Example #4
Source File: PercolateTagProcessor.java From streams with Apache License 2.0 | 6 votes |
/** * 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); } } }
Example #5
Source File: InternalEsClient.java From io with Apache License 2.0 | 6 votes |
/** * インデックスを作成する. * @param index インデックス名 * @param mappings マッピング情報 * @return 非同期応答 */ public ActionFuture<CreateIndexResponse> createIndex(String index, Map<String, JSONObject> mappings) { this.fireEvent(Event.creatingIndex, index); CreateIndexRequestBuilder cirb = new CreateIndexRequestBuilder(esTransportClient.admin().indices()).setIndex(index); // cjkアナライザ設定 ImmutableSettings.Builder indexSettings = ImmutableSettings.settingsBuilder(); indexSettings.put("analysis.analyzer.default.type", "cjk"); cirb.setSettings(indexSettings); if (mappings != null) { for (Map.Entry<String, JSONObject> ent : mappings.entrySet()) { cirb = cirb.addMapping(ent.getKey(), ent.getValue().toString()); } } return cirb.execute(); }
Example #6
Source File: CreateBlobTablePlan.java From crate with Apache License 2.0 | 6 votes |
@Override public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) throws Exception { RelationName relationName = analyzedBlobTable.relationName(); Settings settings = buildSettings( analyzedBlobTable.createBlobTable(), plannerContext.transactionContext(), plannerContext.functions(), params, subQueryResults, numberOfShards); CreateIndexRequest createIndexRequest = new CreateIndexRequest(fullIndexName(relationName.name()), settings); OneRowActionListener<CreateIndexResponse> listener = new OneRowActionListener<>(consumer, r -> new Row1(1L)); dependencies.createIndexAction().execute(createIndexRequest, listener); }
Example #7
Source File: AbstractEsTest.java From test-data-generator with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { if (client.admin().indices().prepareExists(getIndexName()).execute().actionGet().isExists()) { DeleteIndexResponse deleteIndexResponse = client.admin().indices().prepareDelete(getIndexName()) .execute().actionGet(); Assert.assertTrue(deleteIndexResponse.isAcknowledged()); } CreateIndexResponse createIndexResponse = client.admin().indices().prepareCreate(getIndexName()) .execute().actionGet(); Assert.assertTrue(createIndexResponse.isAcknowledged()); for (Map.Entry<String, String> esMapping : getEsMappings().entrySet()) { String esMappingSource = IOUtils.toString( AbstractEsTest.class.getClassLoader().getResourceAsStream(esMapping.getValue())); PutMappingResponse putMappingResponse = client.admin().indices().preparePutMapping(getIndexName()) .setType(esMapping.getKey()).setSource(esMappingSource).execute().actionGet(); Assert.assertTrue(putMappingResponse.isAcknowledged()); } }
Example #8
Source File: ElasticSearchIndex.java From titan1withtp3.1 with Apache License 2.0 | 6 votes |
/** * 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); } }
Example #9
Source File: PluginClient.java From openshift-elasticsearch-plugin with Apache License 2.0 | 6 votes |
public CreateIndexResponse copyIndex(final String index, final String target, Settings settings, String... types) throws InterruptedException, ExecutionException, IOException { return execute(new Callable<CreateIndexResponse>() { @Override public CreateIndexResponse call() throws Exception { LOGGER.trace("Copying {} index to {} for types {}", index, target, types); GetIndexResponse response = getIndices(index); CreateIndexRequestBuilder builder = client.admin().indices().prepareCreate(target); if(settings != null) { builder.setSettings(settings); } for (String type : types) { builder.addMapping(type, response.mappings().get(index).get(type).getSourceAsMap()); } return builder.get(); } }); }
Example #10
Source File: ElasticSearchSink.java From pulsar with Apache License 2.0 | 6 votes |
private void createIndexIfNeeded() throws IOException { GetIndexRequest request = new GetIndexRequest(); request.indices(elasticSearchConfig.getIndexName()); boolean exists = getClient().indices().exists(request); if (!exists) { CreateIndexRequest cireq = new CreateIndexRequest(elasticSearchConfig.getIndexName()); cireq.settings(Settings.builder() .put("index.number_of_shards", elasticSearchConfig.getIndexNumberOfShards()) .put("index.number_of_replicas", elasticSearchConfig.getIndexNumberOfReplicas())); CreateIndexResponse ciresp = getClient().indices().create(cireq); if (!ciresp.isAcknowledged() || !ciresp.isShardsAcknowledged()) { throw new RuntimeException("Unable to create index."); } } }
Example #11
Source File: DefaultElasticSearchAdminService.java From vertx-elasticsearch-service with Apache License 2.0 | 6 votes |
@Override public void createIndex(String index, JsonObject source, CreateIndexOptions options, Handler<AsyncResult<Void>> resultHandler) { final CreateIndexRequestBuilder builder = CreateIndexAction.INSTANCE.newRequestBuilder(service.getClient()) .setIndex(index) .setSource(source.encode(), XContentType.JSON); builder.execute(new ActionListener<CreateIndexResponse>() { @Override public void onResponse(CreateIndexResponse createIndexResponse) { resultHandler.handle(Future.succeededFuture()); } @Override public void onFailure(Exception e) { resultHandler.handle(Future.failedFuture(e)); } }); }
Example #12
Source File: ElasticsearchClientRest.java From c2mon with GNU Lesser General Public License v3.0 | 6 votes |
@Override public boolean createIndex(IndexMetadata indexMetadata, String mapping) { CreateIndexRequest request = new CreateIndexRequest(indexMetadata.getName()); request.settings(Settings.builder() .put("index.number_of_shards", properties.getShardsPerIndex()) .put("index.number_of_replicas", properties.getReplicasPerShard()) ); if (properties.isAutoTemplateMapping()) { request.mapping(TYPE, mapping, XContentType.JSON); } try { CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT); return createIndexResponse.isAcknowledged(); } catch (IOException e) { log.error("Error creating '{}' index on Elasticsearch.", indexMetadata.getName(), e); } return false; }
Example #13
Source File: ElasticsearchClientTransport.java From c2mon with GNU Lesser General Public License v3.0 | 6 votes |
@Override public boolean createIndex(IndexMetadata indexMetadata, String mapping) { CreateIndexRequestBuilder builder = client.admin().indices().prepareCreate(indexMetadata.getName()); builder.setSettings(Settings.builder() .put("number_of_shards", properties.getShardsPerIndex()) .put("number_of_replicas", properties.getReplicasPerShard()) .build()); if (mapping != null) { builder.addMapping(TYPE, mapping, XContentType.JSON); } log.debug("Creating new index with name {}", indexMetadata.getName()); try { CreateIndexResponse response = builder.get(); return response.isAcknowledged(); } catch (ResourceAlreadyExistsException e) { log.debug("Index already exists.", e); } return false; }
Example #14
Source File: TwitterUserstreamElasticsearchIT.java From streams with Apache License 2.0 | 6 votes |
@BeforeClass public void prepareTest() throws Exception { testConfiguration = new StreamsConfigurator<>(TwitterUserstreamElasticsearchConfiguration.class).detectCustomConfiguration(); testClient = ElasticsearchClientManager.getInstance(testConfiguration.getElasticsearch()).client(); ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest(); ClusterHealthResponse clusterHealthResponse = testClient.admin().cluster().health(clusterHealthRequest).actionGet(); assertNotEquals(clusterHealthResponse.getStatus(), ClusterHealthStatus.RED); IndicesExistsRequest indicesExistsRequest = Requests.indicesExistsRequest(testConfiguration.getElasticsearch().getIndex()); IndicesExistsResponse indicesExistsResponse = testClient.admin().indices().exists(indicesExistsRequest).actionGet(); if(indicesExistsResponse.isExists()) { DeleteIndexRequest deleteIndexRequest = Requests.deleteIndexRequest(testConfiguration.getElasticsearch().getIndex()); DeleteIndexResponse deleteIndexResponse = testClient.admin().indices().delete(deleteIndexRequest).actionGet(); assertTrue(deleteIndexResponse.isAcknowledged()); }; CreateIndexRequest createIndexRequest = Requests.createIndexRequest(testConfiguration.getElasticsearch().getIndex()); CreateIndexResponse createIndexResponse = testClient.admin().indices().create(createIndexRequest).actionGet(); assertTrue(createIndexResponse.isAcknowledged()); }
Example #15
Source File: CrudDemo.java From javabase with Apache License 2.0 | 6 votes |
/** * http://es.xiaoleilu.com/010_Intro/25_Tutorial_Indexing.html * http://es.xiaoleilu.com/070_Index_Mgmt/05_Create_Delete.html * 索引相关的 */ private static void index() throws IOException, InterruptedException { // cluster(),产生一个允许从集群中执行action或操作的client; IndicesAdminClient indicesAdminClient = client.admin().indices(); //创建索引 if (checkExistsIndex(indicesAdminClient, INDEX_NAME)) { deleteIndex(indicesAdminClient, INDEX_NAME); } // String settings = getIndexSetting(); // CreateIndexResponse createIndexResponse = indicesAdminClient.prepareCreate(INDEX_NAME).setSettings(settings).execute().actionGet(); CreateIndexResponse createIndexResponse = indicesAdminClient.prepareCreate(INDEX_NAME).setSettings().execute().actionGet(); // log.info("创建索引{}:{}", INDEX_NAME, createIndexResponse.getContext()); //索引的相关配置操作 indexConfig(indicesAdminClient, INDEX_NAME); // indexMapping(indicesAdminClient, INDEX_NAME, TYPE_NAME); }
Example #16
Source File: TransportDeleteAction.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override protected void doExecute(final Task task, final DeleteRequest request, final ActionListener<DeleteResponse> listener) { ClusterState state = clusterService.state(); if (autoCreateIndex.shouldAutoCreate(request.index(), state)) { createIndexAction.execute(task, new CreateIndexRequest(request).index(request.index()).cause("auto(delete api)") .masterNodeTimeout(request.timeout()), new ActionListener<CreateIndexResponse>() { @Override public void onResponse(CreateIndexResponse result) { innerExecute(task, request, listener); } @Override public void onFailure(Throwable e) { if (ExceptionsHelper.unwrapCause(e) instanceof IndexAlreadyExistsException) { // we have the index, do it innerExecute(task, request, listener); } else { listener.onFailure(e); } } }); } else { innerExecute(task, request, listener); } }
Example #17
Source File: ESClient.java From uavstack with Apache License 2.0 | 6 votes |
public boolean creatIndex(String index, String type, Map<String, String> set, Map<String, Map<String, Object>> mapping) throws IOException { CreateIndexRequestBuilder createIndexRequestBuilder = client.admin().indices().prepareCreate(index); if (type != null && mapping != null) { createIndexRequestBuilder.addMapping(type, createMapping(type, mapping)); } if (set != null) { createIndexRequestBuilder.setSettings(createSetting(set)); } CreateIndexResponse resp = createIndexRequestBuilder.execute().actionGet(); if (resp.isAcknowledged()) { return true; } return false; }
Example #18
Source File: BlobAdminClient.java From crate with Apache License 2.0 | 5 votes |
public CompletableFuture<Long> createBlobTable(String tableName, Settings indexSettings) { Settings.Builder builder = Settings.builder(); builder.put(indexSettings); builder.put(SETTING_INDEX_BLOBS_ENABLED.getKey(), true); FutureActionListener<CreateIndexResponse, Long> listener = new FutureActionListener<>(r -> 1L); CreateIndexRequest createIndexRequest = new CreateIndexRequest(fullIndexName(tableName), builder.build()); createIndexAction.execute(createIndexRequest, listener); return listener; }
Example #19
Source File: Elasticsearch7SearchIndex.java From vertexium with Apache License 2.0 | 5 votes |
@SuppressWarnings("unused") protected void createIndex(String indexName) throws IOException { CreateIndexResponse createResponse = client.admin().indices().prepareCreate(indexName) .setSettings(XContentFactory.jsonBuilder() .startObject() .startObject("analysis") .startObject("normalizer") .startObject(LOWERCASER_NORMALIZER_NAME) .field("type", "custom") .array("filter", "lowercase") .endObject() .endObject() .endObject() .field("number_of_shards", getConfig().getNumberOfShards()) .field("number_of_replicas", getConfig().getNumberOfReplicas()) .field("index.mapping.total_fields.limit", getConfig().getIndexMappingTotalFieldsLimit()) .field("refresh_interval", getConfig().getIndexRefreshInterval()) .endObject() ) .execute().actionGet(); ClusterHealthResponse health = client.admin().cluster().prepareHealth(indexName) .setWaitForGreenStatus() .execute().actionGet(); LOGGER.debug("Index status: %s", health.toString()); if (health.isTimedOut()) { LOGGER.warn("timed out waiting for yellow/green index status, for index: %s", indexName); } }
Example #20
Source File: ElasticSearcher.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
private void tryCreateIndex() { if (checkIndexExist()) { return; } CreateIndexRequest request = new CreateIndexRequest(index); try { CreateIndexResponse response = client.indices().create(request, RequestOptions.DEFAULT); if (LogKit.isDebugEnabled()) { LogKit.debug(response.toString()); } } catch (Exception e) { LOG.error(e.toString(), e); } }
Example #21
Source File: ElasticSearcher.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
private void tryCreateIndex() { if (checkIndexExist()) { return; } CreateIndexRequest request = new CreateIndexRequest(index); try { CreateIndexResponse response = client.indices().create(request, RequestOptions.DEFAULT); if (LogKit.isDebugEnabled()) { LogKit.debug(response.toString()); } } catch (Exception e) { LOG.error(e.toString(), e); } }
Example #22
Source File: ElasticSearchClient.java From skywalking with Apache License 2.0 | 5 votes |
public boolean createIndex(String indexName, Map<String, Object> settings, Map<String, Object> mapping) throws IOException { indexName = formatIndexName(indexName); CreateIndexRequest request = new CreateIndexRequest(indexName); Gson gson = new Gson(); request.settings(gson.toJson(settings), XContentType.JSON); request.mapping(TYPE, gson.toJson(mapping), XContentType.JSON); CreateIndexResponse response = client.indices().create(request); log.debug("create {} index finished, isAcknowledged: {}", indexName, response.isAcknowledged()); return response.isAcknowledged(); }
Example #23
Source File: ElasticSearchUtils.java From ElasticUtils with MIT License | 5 votes |
private static CreateIndexResponse internalCreateIndex(Client client, String indexName) throws IOException { final CreateIndexRequestBuilder createIndexRequestBuilder = client .admin() // Get the Admin interface... .indices() // Get the Indices interface... .prepareCreate(indexName); // We want to create a new index .... final CreateIndexResponse indexResponse = createIndexRequestBuilder.execute().actionGet(); if(log.isDebugEnabled()) { log.debug("CreatedIndexResponse: isAcknowledged {}", indexResponse.isAcknowledged()); } return indexResponse; }
Example #24
Source File: EsIndexImpl.java From io with Apache License 2.0 | 5 votes |
@Override CreateIndexResponse onParticularError(ElasticsearchException e) { if (e instanceof IndexAlreadyExistsException || e.getCause() instanceof IndexAlreadyExistsException) { throw new EsClientException.EsIndexAlreadyExistsException(e); } throw e; }
Example #25
Source File: ElasticSearchUtils.java From ElasticUtils with MIT License | 5 votes |
private static CreateIndexResponse internalCreateIndex(Client client, String indexName) throws IOException { final CreateIndexRequestBuilder createIndexRequestBuilder = client .admin() // Get the Admin interface... .indices() // Get the Indices interface... .prepareCreate(indexName); // We want to create a new index .... final CreateIndexResponse indexResponse = createIndexRequestBuilder.execute().actionGet(); if(log.isDebugEnabled()) { log.debug("CreatedIndexResponse: isAcknowledged {}", indexResponse.isAcknowledged()); } return indexResponse; }
Example #26
Source File: ElasticsearchUtil.java From SpringBootLearn with Apache License 2.0 | 5 votes |
/** * 创建索引 * @param index * @return */ public static boolean createIndex(String index) { if (!isIndexExist(index)) { log.info("Index is not exits!"); } CreateIndexResponse indexresponse = client.admin().indices().prepareCreate(index).execute().actionGet(); log.info("执行建立成功?" + indexresponse.isAcknowledged()); return indexresponse.isAcknowledged(); }
Example #27
Source File: ElasticSearchUtils.java From ElasticUtils with MIT License | 5 votes |
private static CreateIndexResponse internalCreateIndex(Client client, String indexName) throws IOException { final CreateIndexRequestBuilder createIndexRequestBuilder = client .admin() // Get the Admin interface... .indices() // Get the Indices interface... .prepareCreate(indexName); // We want to create a new index .... final CreateIndexResponse indexResponse = createIndexRequestBuilder.execute().actionGet(); if(log.isDebugEnabled()) { log.debug("CreatedIndexResponse: isAcknowledged {}", indexResponse.isAcknowledged()); } return indexResponse; }
Example #28
Source File: ElasticSearchUtils.java From ElasticUtils with MIT License | 5 votes |
public static CreateIndexResponse createIndex(Client client, String indexName) { try { return internalCreateIndex(client, indexName); } catch(Exception e) { if(log.isErrorEnabled()) { log.error("Error Creating Index", e); } throw new CreateIndexFailedException(indexName, e); } }
Example #29
Source File: TransportWriterVariant.java From incubator-gobblin with Apache License 2.0 | 5 votes |
@Override public TestClient getTestClient(Config config) throws IOException { final ElasticsearchTransportClientWriter transportClientWriter = new ElasticsearchTransportClientWriter(config); final TransportClient transportClient = transportClientWriter.getTransportClient(); return new TestClient() { @Override public GetResponse get(GetRequest getRequest) throws IOException { try { return transportClient.get(getRequest).get(); } catch (Exception e) { throw new IOException(e); } } @Override public void recreateIndex(String indexName) throws IOException { DeleteIndexRequestBuilder dirBuilder = transportClient.admin().indices().prepareDelete(indexName); try { DeleteIndexResponse diResponse = dirBuilder.execute().actionGet(); } catch (IndexNotFoundException ie) { System.out.println("Index not found... that's ok"); } CreateIndexRequestBuilder cirBuilder = transportClient.admin().indices().prepareCreate(indexName); CreateIndexResponse ciResponse = cirBuilder.execute().actionGet(); Assert.assertTrue(ciResponse.isAcknowledged(), "Create index succeeeded"); } @Override public void close() throws IOException { transportClientWriter.close(); } }; }
Example #30
Source File: AuthService.java From elasticsearch-auth with Apache License 2.0 | 5 votes |
protected void createConstraintIndex(final ActionListener<Void> listener) { client.admin().indices().prepareCreate(constraintIndex) .execute(new ActionListener<CreateIndexResponse>() { @Override public void onResponse(final CreateIndexResponse response) { // TODO health check reload(listener); } @Override public void onFailure(final Throwable e) { listener.onFailure(e); } }); }