use of org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest in project storm-elastic-search by hmsonline.
the class ElasticSearchState method createIndices.
public void createIndices(TridentElasticSearchMapper mapper, List<TridentTuple> tuples) {
BulkRequestBuilder bulkRequest = client.prepareBulk();
Set<String> existingIndex = new HashSet<String>();
for (TridentTuple tuple : tuples) {
String indexName = mapper.mapToIndex(tuple);
String type = mapper.mapToType(tuple);
String key = mapper.mapToKey(tuple);
Map<String, Object> data = mapper.mapToData(tuple);
String parentId = mapper.mapToParentId(tuple);
if (!existingIndex.contains(indexName) && !client.admin().indices().exists(new IndicesExistsRequest(indexName)).actionGet().isExists()) {
createIndex(bulkRequest, indexName, mapper.mapToIndexSettings(tuple));
createMapping(bulkRequest, indexName, type, mapper.mapToMappingSettings(tuple));
existingIndex.add(indexName);
}
if (StringUtils.isBlank(parentId)) {
bulkRequest.add(client.prepareIndex(indexName, type, key).setSource(data));
} else {
LOGGER.debug("parent: " + parentId);
bulkRequest.add(client.prepareIndex(indexName, type, key).setSource(data).setParent(parentId));
}
}
try {
BulkResponse bulkResponse = bulkRequest.execute().actionGet();
if (bulkResponse.hasFailures()) {
// Index failed. Retry!
throw new FailedException("Cannot create index via ES: " + bulkResponse.buildFailureMessage());
}
} catch (ElasticSearchException e) {
StormElasticSearchUtils.handleElasticSearchException(getClass(), e);
}
}
use of org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest in project crate by crate.
the class TransportExecutorDDLTest method testCreateTableWithOrphanedAlias.
@Test
public void testCreateTableWithOrphanedAlias() throws Exception {
String partitionName = new PartitionName("test", Collections.singletonList(new BytesRef("foo"))).asIndexName();
client().admin().indices().prepareCreate(partitionName).addMapping(Constants.DEFAULT_MAPPING_TYPE, TEST_PARTITIONED_MAPPING).setSettings(TEST_SETTINGS).addAlias(new Alias("test")).execute().actionGet();
ensureGreen();
execute("create table test (id integer, name string, names string) " + "clustered into 2 shards " + "partitioned by (id) with (number_of_replicas=0)");
assertThat(response.rowCount(), is(1L));
ensureGreen();
execute("select * from information_schema.tables where table_name = 'test'");
assertThat(response.rowCount(), is(1L));
execute("select count(*) from information_schema.columns where table_name = 'test'");
assertThat((Long) response.rows()[0][0], is(3L));
// check that orphaned alias has been deleted
assertThat(client().admin().cluster().prepareState().execute().actionGet().getState().metaData().hasAlias("test"), is(false));
// check that orphaned partition has been deleted
assertThat(client().admin().indices().exists(new IndicesExistsRequest(partitionName)).actionGet().isExists(), is(false));
}
use of org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest in project crate by crate.
the class TransportExecutorDDLTest method testCreateTableWithOrphanedPartitions.
@Test
public void testCreateTableWithOrphanedPartitions() throws Exception {
String partitionName = new PartitionName("test", Collections.singletonList(new BytesRef("foo"))).asIndexName();
client().admin().indices().prepareCreate(partitionName).addMapping(Constants.DEFAULT_MAPPING_TYPE, TEST_PARTITIONED_MAPPING).setSettings(TEST_SETTINGS).execute().actionGet();
ensureGreen();
execute("create table test (id integer, name string, names string) partitioned by (id)");
ensureYellow();
execute("select * from information_schema.tables where table_name = 'test'");
assertThat(response.rowCount(), is(1L));
execute("select count(*) from information_schema.columns where table_name = 'test'");
assertThat((Long) response.rows()[0][0], is(3L));
// check that orphaned partition has been deleted
assertThat(client().admin().indices().exists(new IndicesExistsRequest(partitionName)).actionGet().isExists(), is(false));
}
use of org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest in project crate by crate.
the class DDLIntegrationTest method testCreateTableWithRefreshIntervalDisableRefresh.
@Test
public void testCreateTableWithRefreshIntervalDisableRefresh() throws Exception {
execute("create table test (id int primary key, content string) " + "clustered into 5 shards " + "with (refresh_interval=0, number_of_replicas = 0)");
ensureYellow();
assertTrue(client().admin().indices().exists(new IndicesExistsRequest("test")).actionGet().isExists());
String expectedSettings = "{\"test\":{" + "\"settings\":{" + "\"index.number_of_replicas\":\"0\"," + "\"index.number_of_shards\":\"5\"," + "\"index.refresh_interval\":\"0ms\"," + "\"index.version.created\":\"" + Version.CURRENT.esVersion.id + "\"" + "}}}";
JSONAssert.assertEquals(expectedSettings, getIndexSettings("test"), false);
execute("ALTER TABLE test SET (refresh_interval = 5000)");
String expectedSetSettings = "{\"test\":{" + "\"settings\":{" + "\"index.number_of_replicas\":\"0\"," + "\"index.number_of_shards\":\"5\"," + "\"index.refresh_interval\":\"5000ms\"," + "\"index.version.created\":\"" + Version.CURRENT.esVersion.id + "\"" + "}}}";
JSONAssert.assertEquals(expectedSetSettings, getIndexSettings("test"), false);
execute("ALTER TABLE test RESET (refresh_interval)");
String expectedResetSettings = "{\"test\":{" + "\"settings\":{" + "\"index.number_of_replicas\":\"0\"," + "\"index.number_of_shards\":\"5\"," + "\"index.refresh_interval\":\"1000ms\"," + "\"index.version.created\":\"" + Version.CURRENT.esVersion.id + "\"" + "}}}";
JSONAssert.assertEquals(expectedResetSettings, getIndexSettings("test"), false);
}
use of org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest in project crate by crate.
the class DDLIntegrationTest method testCreateTable.
@Test
public void testCreateTable() throws Exception {
execute("create table test (col1 integer primary key, col2 string) " + "clustered into 5 shards with (number_of_replicas = 1)");
ensureYellow();
assertTrue(client().admin().indices().exists(new IndicesExistsRequest("test")).actionGet().isExists());
String expectedMapping = "{\"default\":{" + "\"dynamic\":\"true\",\"_meta\":{\"routing_hash_function\":\"org.elasticsearch.cluster.routing.Murmur3HashFunction\",\"primary_keys\":[\"col1\"]," + "\"version\":{\"created\":{\"elasticsearch\":" + Version.CURRENT.esVersion.id + ",\"cratedb\":" + Version.CURRENT.id + "}}}," + "\"_all\":{\"enabled\":false}," + "\"dynamic_templates\":[{\"strings\":{\"mapping\":{\"index\":\"not_analyzed\",\"store\":false,\"type\":\"string\",\"doc_values\":true},\"match_mapping_type\":\"string\"}}]," + "\"properties\":{" + "\"col1\":{\"type\":\"integer\"},\"col2\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}}";
String expectedSettings = "{\"test\":{" + "\"settings\":{" + "\"index.number_of_replicas\":\"1\"," + "\"index.number_of_shards\":\"5\"," + "\"index.version.created\":\"" + Version.CURRENT.esVersion.id + "\"" + "}}}";
assertEquals(expectedMapping, getIndexMapping("test"));
JSONAssert.assertEquals(expectedSettings, getIndexSettings("test"), false);
// test index usage
execute("insert into test (col1, col2) values (1, 'foo')");
assertEquals(1, response.rowCount());
refresh();
execute("SELECT * FROM test");
assertEquals(1L, response.rowCount());
}
Aggregations