public void createIndexIfNotExists(String indexName, final int shards, final int replicas) { // create an index if not existent if (!this.elasticsearchClient.admin().indices().prepareExists(indexName).execute().actionGet().isExists()) { Settings.Builder settings = Settings.builder() .put("number_of_shards", shards) .put("number_of_replicas", replicas); this.elasticsearchClient.admin().indices().prepareCreate(indexName) .setSettings(settings) .setUpdateAllTypes(true) .execute().actionGet(); } else { //LOGGER.debug("Index with name {} already exists", indexName); } }
public static long getIndexCount(Client client, MongoDBRiverDefinition definition) { if (client.admin().indices().prepareExists(definition.getIndexName()).get().isExists()) { if (definition.isImportAllCollections()) { return client.prepareCount(definition.getIndexName()).execute().actionGet().getCount(); } else { if (client.admin().indices().prepareTypesExists(definition.getIndexName()).setTypes(definition.getTypeName()).get() .isExists()) { return client.prepareCount(definition.getIndexName()).setTypes(definition.getTypeName()).get().getCount(); } } } return 0; }
IndicesExistsRequestBuilder indicesExistBld = admin.indices().prepareExists( tempMeta.getIndex() ); IndicesExistsResponse indicesExistResponse = indicesExistBld.execute().get(); if ( !indicesExistResponse.isExists() ) {
if (!esClient.admin().indices().prepareExists(definition.getIndexName()).get().isExists()) { esClient.admin().indices().prepareCreate(definition.getIndexName()).get();
/** * create a new index. This method must be called to ensure that an elasticsearch index is available and can be used. * @param indexName * @param shards * @param replicas * @throws NoNodeAvailableException in case that no elasticsearch server can be contacted. */ public void createIndexIfNotExists(String indexName, final int shards, final int replicas) throws NoNodeAvailableException { // create an index if not existent if (!this.elasticsearchClient.admin().indices().prepareExists(indexName).execute().actionGet().isExists()) { Settings.Builder settings = Settings.builder() .put("number_of_shards", shards) .put("number_of_replicas", replicas); this.elasticsearchClient.admin().indices().prepareCreate(indexName) .setSettings(settings) .setUpdateAllTypes(true) .execute().actionGet(); } else { //LOGGER.debug("Index with name {} already exists", indexName); } }
/** * Check if an index already exists * @param client Elasticsearch client * @param index Index name * @return true if index already exists */ @Deprecated public static boolean isIndexExist(Client client, String index) { return client.admin().indices().prepareExists(index).get().isExists(); }
/** * Check if an index already exists * @param client Elasticsearch client * @param index Index name * @return true if index already exists */ @Deprecated public static boolean isIndexExist(Client client, String index) { return client.admin().indices().prepareExists(index).get().isExists(); }
@Override public Boolean check() throws Exception { try { getClient().admin().indices().prepareExists(elasticSearchClusterName).execute(); return true; } catch (Exception e) { return false; } }
private static void createIndex(Client client) { boolean exist = client.admin().indices().prepareExists("hackaton").execute().actionGet().isExists(); if (!exist) { client.admin().indices().prepareCreate("hackaton").execute().actionGet(); } }
@Override public boolean existsTable(SchemaTableName schemaTableName) { return client.admin().indices().prepareExists(schemaTableName.getTableName()) .execute().actionGet().isExists(); }
@Override public boolean isIndexExists(final String indexName) { return searchClientService.getClient().admin().indices() .prepareExists(indexName).get().isExists(); }
/** * Initialize the index in the Elasticsearch cluster with the current settings. */ @PostConstruct public void initializeIndex() { if (!this.client.admin().indices().prepareExists(index).get().isExists()) { this.client.admin().indices().prepareCreate(index).setSource(settings).get(); } }
/** * Returns <code>true</code> iff the given index exists otherwise <code>false</code> */ protected boolean indexExists(String index) { IndicesExistsResponse actionGet = client().admin().indices().prepareExists(index).execute().actionGet(); return actionGet.isExists(); }
private void initNativeClient() { esClient = NodeBuilder.nodeBuilder().client(true).node().client(); boolean indexExists = esClient.admin().indices().prepareExists(indexName).execute().actionGet().isExists(); if (indexExists) { esClient.admin().indices().prepareDelete(indexName).execute().actionGet(); } esClient.admin().indices().prepareCreate(indexName).execute().actionGet(); }
@Override public boolean existsTable(SchemaTableName schemaTableName) { return client.admin().indices().prepareExists(schemaTableName.getTableName()) .execute().actionGet().isExists(); }
@Override public Boolean execute(Client client) throws ElasticsearchException { if ((index != null) && (type != null) && (id != null)) { // Check if a document exists GetResponse response = client.prepareGet(index, type, id).setRefresh(true).execute().actionGet(); return response.isExists(); } else { // Check if index exists IndicesExistsResponse response = client.admin().indices().prepareExists(index).execute().actionGet(); return response.isExists(); } }
@Override public Boolean execute(Client client) throws ElasticsearchException { if ((index != null) && (type != null) && (id != null)) { // Check if a document exists GetResponse response = client.prepareGet(index, type, id).setRefresh(true).execute().actionGet(); return response.isExists(); } else { // Check if index exists IndicesExistsResponse response = client.admin().indices().prepareExists(index).execute().actionGet(); return response.isExists(); } }
private void deleteIndex(final String indexName) { bulkProcessor.flush(); // make sure dangling requests don't resurrect this index IndicesAdminClient indices = indicesAdminClient(); if (indices.prepareExists(indexName).execute().actionGet().isExists()) { indices.prepareDelete(indexName).execute().actionGet(); } }
@After public void after() { final IndicesAdminClient indices = client.admin().indices(); if(indices.prepareExists(INDEX).execute().actionGet().isExists()) { indices.prepareDelete(INDEX).execute().actionGet(); } } }
@After public void after() { final IndicesAdminClient indices = client.admin().indices(); if(indices.prepareExists(INDEX).execute().actionGet().isExists()) { indices.prepareDelete(INDEX).execute().actionGet(); } } }