org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse Java Examples
The following examples show how to use
org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse.
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: PartitionedTableIntegrationTest.java From crate with Apache License 2.0 | 6 votes |
@Test public void testDropPartitionedTable() throws Exception { execute("create table quotes (" + " id integer, " + " quote string, " + " date timestamp with time zone" + ") partitioned by (date) with (number_of_replicas=0)"); ensureYellow(); execute("insert into quotes (id, quote, date) values(?, ?, ?), (?, ?, ?)", new Object[]{1, "Don't panic", 1395874800000L, 2, "Time is an illusion. Lunchtime doubly so", 1395961200000L}); ensureYellow(); refresh(); execute("drop table quotes"); assertEquals(1L, response.rowCount()); GetIndexTemplatesResponse getIndexTemplatesResponse = client().admin().indices() .prepareGetTemplates(PartitionName.templateName(Schemas.DOC_SCHEMA_NAME, "quotes")).execute().get(); assertThat(getIndexTemplatesResponse.getIndexTemplates().size(), is(0)); ClusterState state = internalCluster().clusterService().state(); assertThat(state.metaData().indices().size(), is(0)); assertThat(state.metaData().hasAlias("quotes"), is(false)); }
Example #2
Source File: PartitionedTableIntegrationTest.java From crate with Apache License 2.0 | 6 votes |
@Test public void testAlterTableResetEmptyPartitionedTable() { execute("create table quotes (id integer, quote string, date timestamp with time zone) " + "partitioned by(date) clustered into 3 shards with (number_of_replicas='1')"); ensureYellow(); String templateName = PartitionName.templateName(sqlExecutor.getCurrentSchema(), "quotes"); GetIndexTemplatesResponse templatesResponse = client().admin().indices() .prepareGetTemplates(templateName).execute().actionGet(); Settings templateSettings = templatesResponse.getIndexTemplates().get(0).getSettings(); assertThat(templateSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0), is(1)); assertThat(templateSettings.get(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS), is("false")); execute("alter table quotes reset (number_of_replicas)"); ensureYellow(); templatesResponse = client().admin().indices() .prepareGetTemplates(templateName).execute().actionGet(); templateSettings = templatesResponse.getIndexTemplates().get(0).getSettings(); assertThat(templateSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0), is(0)); assertThat(templateSettings.get(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS), is("0-1")); }
Example #3
Source File: TestCluster.java From crate with Apache License 2.0 | 6 votes |
/** * Removes all templates, except the templates defined in the exclude */ public void wipeAllTemplates(Set<String> exclude) { if (size() > 0) { GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates().get(); for (IndexTemplateMetaData indexTemplate : response.getIndexTemplates()) { if (exclude.contains(indexTemplate.getName())) { continue; } try { client().admin().indices().prepareDeleteTemplate(indexTemplate.getName()).execute().actionGet(); } catch (IndexTemplateMissingException e) { // ignore } } } }
Example #4
Source File: RestHeadIndexTemplateAction.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { GetIndexTemplatesRequest getIndexTemplatesRequest = new GetIndexTemplatesRequest(request.param("name")); getIndexTemplatesRequest.local(request.paramAsBoolean("local", getIndexTemplatesRequest.local())); getIndexTemplatesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getIndexTemplatesRequest.masterNodeTimeout())); client.admin().indices().getTemplates(getIndexTemplatesRequest, new RestResponseListener<GetIndexTemplatesResponse>(channel) { @Override public RestResponse buildResponse(GetIndexTemplatesResponse getIndexTemplatesResponse) { boolean templateExists = getIndexTemplatesResponse.getIndexTemplates().size() > 0; if (templateExists) { return new BytesRestResponse(OK); } else { return new BytesRestResponse(NOT_FOUND); } } }); }
Example #5
Source File: PartitionedTableIntegrationTest.java From crate with Apache License 2.0 | 6 votes |
@Test @UseRandomizedSchema(random = false) public void testAlterTableAddColumnOnPartitionedTableWithoutPartitions() throws Exception { execute("create table t (id int primary key, date timestamp with time zone primary key) " + "partitioned by (date) " + "clustered into 1 shards " + "with (number_of_replicas=0)"); ensureYellow(); execute("alter table t add column name string"); execute("alter table t add column ft_name string index using fulltext"); ensureYellow(); execute("select * from t"); assertThat(Arrays.asList(response.cols()), Matchers.containsInAnyOrder("date", "ft_name", "id", "name")); GetIndexTemplatesResponse templatesResponse = client().admin().indices().getTemplates(new GetIndexTemplatesRequest(".partitioned.t.")).actionGet(); IndexTemplateMetaData metaData = templatesResponse.getIndexTemplates().get(0); String mappingSource = metaData.mappings().get(DEFAULT_MAPPING_TYPE).toString(); Map mapping = (Map) XContentFactory.xContent(mappingSource) .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, mappingSource) .map() .get(DEFAULT_MAPPING_TYPE); assertNotNull(((Map) mapping.get("properties")).get("name")); assertNotNull(((Map) mapping.get("properties")).get("ft_name")); }
Example #6
Source File: ElasticSearchDAOV6.java From conductor with Apache License 2.0 | 5 votes |
private void initIndexTemplate(String type) { String template = "template_" + type; GetIndexTemplatesResponse result = elasticSearchClient.admin().indices().prepareGetTemplates(template).execute().actionGet(); if (result.getIndexTemplates().isEmpty()) { LOGGER.info("Creating the index template '{}'", template); try { String templateSource = loadTypeMappingSource("/" + template + ".json"); elasticSearchClient.admin().indices().preparePutTemplate(template).setSource(templateSource.getBytes(), XContentType.JSON).execute().actionGet(); } catch (Exception e) { LOGGER.error("Failed to init " + template, e); } } }
Example #7
Source File: ElasticsearchAssertions.java From crate with Apache License 2.0 | 5 votes |
/** * Assert that an index template exists */ public static void assertIndexTemplateExists(GetIndexTemplatesResponse templatesResponse, String name) { List<String> templateNames = new ArrayList<>(); for (IndexTemplateMetaData indexTemplateMetaData : templatesResponse.getIndexTemplates()) { templateNames.add(indexTemplateMetaData.name()); } assertThat(templateNames, hasItem(name)); }
Example #8
Source File: ElasticsearchAssertions.java From crate with Apache License 2.0 | 5 votes |
/** * Assert that an index template is missing */ public static void assertIndexTemplateMissing(GetIndexTemplatesResponse templatesResponse, String name) { List<String> templateNames = new ArrayList<>(); for (IndexTemplateMetaData indexTemplateMetaData : templatesResponse.getIndexTemplates()) { templateNames.add(indexTemplateMetaData.name()); } assertThat(templateNames, not(hasItem(name))); }
Example #9
Source File: PartitionedTableIntegrationTest.java From crate with Apache License 2.0 | 5 votes |
@Test @UseRandomizedSchema(random = false) public void testAlterTableAddColumnOnPartitionedTable() throws Exception { execute("create table t (id int primary key, date timestamp with time zone primary key) " + "partitioned by (date) " + "clustered into 1 shards " + "with (number_of_replicas=0)"); execute("insert into t (id, date) values (1, '2014-01-01')"); execute("insert into t (id, date) values (10, '2015-01-01')"); ensureYellow(); refresh(); execute("alter table t add name string"); execute("select * from t"); assertThat(Arrays.asList(response.cols()), Matchers.containsInAnyOrder("date", "id", "name")); GetIndexTemplatesResponse templatesResponse = client().admin().indices().getTemplates(new GetIndexTemplatesRequest(".partitioned.t.")).actionGet(); IndexTemplateMetaData metaData = templatesResponse.getIndexTemplates().get(0); String mappingSource = metaData.mappings().get(DEFAULT_MAPPING_TYPE).toString(); Map mapping = (Map) XContentFactory.xContent(mappingSource) .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, mappingSource) .map().get(DEFAULT_MAPPING_TYPE); assertNotNull(((Map) mapping.get("properties")).get("name")); // template order must not be touched assertThat(metaData.order(), is(100)); }
Example #10
Source File: PartitionedTableIntegrationTest.java From crate with Apache License 2.0 | 5 votes |
@Test public void testAlterPartitionedTablePartition() { execute("create table quotes (id integer, quote string, date timestamp with time zone) " + "partitioned by(date) clustered into 3 shards with (number_of_replicas=0)"); ensureYellow(); execute("insert into quotes (id, quote, date) values (?, ?, ?), (?, ?, ?)", new Object[]{1, "Don't panic", 1395874800000L, 2, "Now panic", 1395961200000L} ); assertThat(response.rowCount(), is(2L)); ensureYellow(); refresh(); execute("alter table quotes partition (date=1395874800000) set (number_of_replicas=1)"); ensureYellow(); execute("select partition_ident, number_of_replicas from information_schema.table_partitions order by 1"); assertThat( printedTable(response.rows()), is("04732cpp6ks3ed1o60o30c1g| 1\n" + "04732cpp6ksjcc9i60o30c1g| 0\n") ); String templateName = PartitionName.templateName(sqlExecutor.getCurrentSchema(), "quotes"); GetIndexTemplatesResponse templatesResponse = client().admin().indices() .prepareGetTemplates(templateName).execute().actionGet(); Settings templateSettings = templatesResponse.getIndexTemplates().get(0).getSettings(); assertThat(templateSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0), is(0)); assertThat(templateSettings.get(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS), is("false")); }
Example #11
Source File: DDLIntegrationTest.java From crate with Apache License 2.0 | 5 votes |
@Test public void testAlterShardsOfPartitionedTableAffectsNewPartitions() { execute( "create table quotes (" + " id integer," + " quote string," + " date timestamp with time zone" + ") partitioned by(date) " + "clustered into 3 shards with (number_of_replicas='0-all')"); ensureYellow(); execute("insert into quotes (id, quote, date) values (?, ?, ?), (?, ?, ?)", new Object[]{ 1, "Don't panic", 1395874800000L, 2, "Now panic", 1395961200000L} ); execute("alter table quotes set (number_of_shards=5)"); String templateName = PartitionName.templateName(Schemas.DOC_SCHEMA_NAME, "quotes"); GetIndexTemplatesResponse templatesResponse = client().admin().indices().prepareGetTemplates(templateName).execute().actionGet(); Settings templateSettings = templatesResponse.getIndexTemplates().get(0).getSettings(); assertThat(templateSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 0), is(5)); execute("insert into quotes (id, quote, date) values (?, ?, ?)", new Object[]{3, "Time is a illusion. Lunchtime doubles so", 1495961200000L} ); PartitionName partitionName = new PartitionName( new RelationName("doc", "quotes"), Arrays.asList("1495961200000")); execute("select number_of_shards from information_schema.table_partitions where partition_ident = ? and table_name = ?", $(partitionName.ident(), partitionName.relationName().name())); assertThat(response.rows()[0][0], is(5)); }
Example #12
Source File: ElasticSearchDAOV5.java From conductor with Apache License 2.0 | 5 votes |
/** * Initializes the index with required templates and mappings. */ private void initIndex() throws Exception { // 0. Add the tasklog template GetIndexTemplatesResponse result = elasticSearchClient.admin() .indices() .prepareGetTemplates("tasklog_template") .execute() .actionGet(); if (result.getIndexTemplates().isEmpty()) { logger.info("Creating the index template 'tasklog_template'"); InputStream stream = ElasticSearchDAOV5.class .getResourceAsStream("/template_tasklog.json"); byte[] templateSource = IOUtils.toByteArray(stream); try { elasticSearchClient.admin() .indices() .preparePutTemplate("tasklog_template") .setSource(templateSource, XContentType.JSON) .execute() .actionGet(); } catch (Exception e) { logger.error("Failed to init tasklog_template", e); } } }
Example #13
Source File: RestGetIndexTemplateAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { final String[] names = Strings.splitStringByCommaToArray(request.param("name")); GetIndexTemplatesRequest getIndexTemplatesRequest = new GetIndexTemplatesRequest(names); getIndexTemplatesRequest.local(request.paramAsBoolean("local", getIndexTemplatesRequest.local())); getIndexTemplatesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getIndexTemplatesRequest.masterNodeTimeout())); final boolean implicitAll = getIndexTemplatesRequest.names().length == 0; client.admin().indices().getTemplates(getIndexTemplatesRequest, new RestBuilderListener<GetIndexTemplatesResponse>(channel) { @Override public RestResponse buildResponse(GetIndexTemplatesResponse getIndexTemplatesResponse, XContentBuilder builder) throws Exception { boolean templateExists = getIndexTemplatesResponse.getIndexTemplates().size() > 0; Map<String, String> paramsMap = Maps.newHashMap(); paramsMap.put("reduce_mappings", "true"); ToXContent.Params params = new ToXContent.DelegatingMapParams(paramsMap, request); builder.startObject(); for (IndexTemplateMetaData indexTemplateMetaData : getIndexTemplatesResponse.getIndexTemplates()) { IndexTemplateMetaData.Builder.toXContent(indexTemplateMetaData, builder, params); } builder.endObject(); RestStatus restStatus = (templateExists || implicitAll) ? OK : NOT_FOUND; return new BytesRestResponse(restStatus, builder); } }); }
Example #14
Source File: ColumnPolicyIntegrationTest.java From crate with Apache License 2.0 | 5 votes |
@Test public void testStrictPartitionedTableInsert() throws Exception { execute("create table numbers (" + " num int, " + " odd boolean," + " prime boolean" + ") partitioned by (odd) with (column_policy='strict', number_of_replicas=0)"); ensureYellow(); GetIndexTemplatesResponse response = client().admin().indices() .prepareGetTemplates(PartitionName.templateName(sqlExecutor.getCurrentSchema(), "numbers")) .execute().actionGet(); assertThat(response.getIndexTemplates().size(), is(1)); IndexTemplateMetaData template = response.getIndexTemplates().get(0); CompressedXContent mappingStr = template.mappings().get(Constants.DEFAULT_MAPPING_TYPE); assertThat(mappingStr, is(notNullValue())); Tuple<XContentType, Map<String, Object>> typeAndMap = XContentHelper.convertToMap(mappingStr.compressedReference(), false, XContentType.JSON); @SuppressWarnings("unchecked") Map<String, Object> mapping = (Map<String, Object>) typeAndMap.v2().get(Constants.DEFAULT_MAPPING_TYPE); assertThat(decodeMappingValue(mapping.get("dynamic")), is(ColumnPolicy.STRICT)); execute("insert into numbers (num, odd, prime) values (?, ?, ?)", new Object[]{6, true, false}); execute("refresh table numbers"); Map<String, Object> sourceMap = getSourceMap( new PartitionName(new RelationName("doc", "numbers"), Arrays.asList("true")).asIndexName()); assertThat(decodeMappingValue(sourceMap.get("dynamic")), is(ColumnPolicy.STRICT)); expectedException.expect(SQLActionException.class); expectedException.expectMessage("Column perfect unknown"); execute("insert into numbers (num, odd, prime, perfect) values (?, ?, ?, ?)", new Object[]{28, true, false, true}); }
Example #15
Source File: ColumnPolicyIntegrationTest.java From crate with Apache License 2.0 | 5 votes |
@Test public void testStrictPartitionedTableUpdate() throws Exception { execute("create table numbers (" + " num int, " + " odd boolean," + " prime boolean" + ") partitioned by (odd) with (column_policy='strict', number_of_replicas=0)"); ensureYellow(); GetIndexTemplatesResponse response = client().admin().indices() .prepareGetTemplates(PartitionName.templateName(sqlExecutor.getCurrentSchema(), "numbers")) .execute().actionGet(); assertThat(response.getIndexTemplates().size(), is(1)); IndexTemplateMetaData template = response.getIndexTemplates().get(0); CompressedXContent mappingStr = template.mappings().get(Constants.DEFAULT_MAPPING_TYPE); assertThat(mappingStr, is(notNullValue())); Tuple<XContentType, Map<String, Object>> typeAndMap = XContentHelper.convertToMap(mappingStr.compressedReference(), false); @SuppressWarnings("unchecked") Map<String, Object> mapping = (Map<String, Object>) typeAndMap.v2().get(Constants.DEFAULT_MAPPING_TYPE); assertThat(decodeMappingValue(mapping.get("dynamic")), is(ColumnPolicy.STRICT)); execute("insert into numbers (num, odd, prime) values (?, ?, ?)", new Object[]{6, true, false}); execute("refresh table numbers"); Map<String, Object> sourceMap = getSourceMap( new PartitionName(new RelationName("doc", "numbers"), Arrays.asList("true")).asIndexName()); assertThat(decodeMappingValue(sourceMap.get("dynamic")), is(ColumnPolicy.STRICT)); expectedException.expect(SQLActionException.class); expectedException.expectMessage("Column perfect unknown"); execute("update numbers set num=?, perfect=? where num=6", new Object[]{28, true}); }
Example #16
Source File: PartitionedTableIntegrationTest.java From crate with Apache License 2.0 | 5 votes |
@Test public void testAlterTableResetPartitionedTable() throws Exception { execute("create table quotes (id integer, quote string, date timestamp with time zone) " + "partitioned by(date) clustered into 3 shards with( number_of_replicas = '1-all')"); ensureYellow(); execute("insert into quotes (id, quote, date) values (?, ?, ?), (?, ?, ?)", new Object[]{1, "Don't panic", 1395874800000L, 2, "Now panic", 1395961200000L} ); assertThat(response.rowCount(), is(2L)); ensureYellow(); refresh(); execute("alter table quotes reset (number_of_replicas)"); ensureYellow(); String templateName = PartitionName.templateName(sqlExecutor.getCurrentSchema(), "quotes"); GetIndexTemplatesResponse templatesResponse = client().admin().indices() .prepareGetTemplates(templateName).execute().actionGet(); Settings templateSettings = templatesResponse.getIndexTemplates().get(0).getSettings(); assertThat(templateSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0), is(0)); assertThat(templateSettings.get(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS), is("0-1")); assertBusy(() -> { execute("select number_of_replicas from information_schema.table_partitions"); assertThat( printedTable(response.rows()), is("0-1\n" + "0-1\n")); }); }
Example #17
Source File: PartitionedTableIntegrationTest.java From crate with Apache License 2.0 | 4 votes |
@Test public void testAlterNumberOfShards() { execute("create table quotes (" + " id integer, " + " quote string, " + " date timestamp with time zone) " + "partitioned by(date) clustered into 3 shards with (number_of_replicas='0-all')"); ensureYellow(); String templateName = PartitionName.templateName(sqlExecutor.getCurrentSchema(), "quotes"); GetIndexTemplatesResponse templatesResponse = client().admin().indices() .prepareGetTemplates(templateName).execute().actionGet(); Settings templateSettings = templatesResponse.getIndexTemplates().get(0).getSettings(); assertThat(templateSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 0), is(3)); execute("alter table quotes set (number_of_shards=6)"); ensureGreen(); templatesResponse = client().admin().indices() .prepareGetTemplates(templateName).execute().actionGet(); templateSettings = templatesResponse.getIndexTemplates().get(0).getSettings(); assertThat(templateSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 0), is(6)); execute("insert into quotes (id, quote, date) values (?, ?, ?)", new Object[]{1, "Don't panic", 1395874800000L} ); assertThat(response.rowCount(), is(1L)); refresh(); assertTrue(clusterService().state().metaData().hasAlias(getFqn("quotes"))); execute("select number_of_replicas, number_of_shards from information_schema.tables where table_name = 'quotes'"); assertEquals("0-all", response.rows()[0][0]); assertEquals(6, response.rows()[0][1]); execute("select number_of_shards from information_schema.table_partitions where table_name='quotes'"); assertThat(response.rowCount(), is(1L)); assertThat((Integer) response.rows()[0][0], is(6)); execute("alter table quotes set (number_of_shards=2)"); ensureYellow(); execute("insert into quotes (id, quote, date) values (?, ?, ?)", new Object[]{2, "Now panic", 1395961200000L} ); assertThat(response.rowCount(), is(1L)); ensureYellow(); refresh(); execute("select number_of_replicas, number_of_shards from information_schema.tables where table_name = 'quotes'"); assertEquals("0-all", response.rows()[0][0]); assertEquals(2, response.rows()[0][1]); execute("select partition_ident, number_of_shards from information_schema.table_partitions " + "where table_name = 'quotes' order by number_of_shards ASC"); assertThat( printedTable(response.rows()), is("04732cpp6ksjcc9i60o30c1g| 2\n" + "04732cpp6ks3ed1o60o30c1g| 6\n") ); templatesResponse = client().admin().indices() .prepareGetTemplates(templateName).execute().actionGet(); templateSettings = templatesResponse.getIndexTemplates().get(0).getSettings(); assertThat(templateSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 0), is(2)); }
Example #18
Source File: ColumnPolicyIntegrationTest.java From crate with Apache License 2.0 | 4 votes |
@Test public void testAlterColumnPolicyOnPartitionedTableWithExistingPartitions() throws Exception { execute("create table dynamic_table (" + " id integer, " + " score double" + ") partitioned by (score) with (number_of_replicas=0, column_policy='strict')"); ensureYellow(); // create at least 2 partitions to test real multi partition logic (1 partition would behave similar to 1 normal table) execute("insert into dynamic_table (id, score) values (1, 10)"); execute("insert into dynamic_table (id, score) values (1, 20)"); execute("refresh table dynamic_table"); ensureYellow(); execute("alter table dynamic_table set (column_policy = 'dynamic')"); waitNoPendingTasksOnAll(); // After changing the column_policy it's possible to add new columns to existing and new // partitions execute("insert into dynamic_table (id, score, comment) values (2, 10, 'this is a new column')"); execute("insert into dynamic_table (id, score, new_comment) values (2, 5, 'this is a new column on a new partition')"); execute("refresh table dynamic_table"); ensureYellow(); GetIndexTemplatesResponse response = client().admin().indices() .prepareGetTemplates(PartitionName.templateName(sqlExecutor.getCurrentSchema(), "dynamic_table")) .execute().actionGet(); assertThat(response.getIndexTemplates().size(), is(1)); IndexTemplateMetaData template = response.getIndexTemplates().get(0); CompressedXContent mappingStr = template.mappings().get(Constants.DEFAULT_MAPPING_TYPE); assertThat(mappingStr, is(notNullValue())); Tuple<XContentType, Map<String, Object>> typeAndMap = XContentHelper.convertToMap(mappingStr.compressedReference(), false, XContentType.JSON); @SuppressWarnings("unchecked") Map<String, Object> mapping = (Map<String, Object>) typeAndMap.v2().get(Constants.DEFAULT_MAPPING_TYPE); assertThat(decodeMappingValue(mapping.get("dynamic")), is(ColumnPolicy.DYNAMIC)); execute("insert into dynamic_table (id, score, new_col) values (?, ?, ?)", new Object[]{6, 3, "hello"}); execute("refresh table dynamic_table"); ensureYellow(); Map<String, Object> sourceMap = getSourceMap( new PartitionName(new RelationName("doc", "dynamic_table"), Arrays.asList("10.0")).asIndexName()); assertThat(decodeMappingValue(sourceMap.get("dynamic")), is(ColumnPolicy.DYNAMIC)); sourceMap = getSourceMap(new PartitionName( new RelationName("doc", "dynamic_table"), Arrays.asList("5.0")).asIndexName()); assertThat(decodeMappingValue(sourceMap.get("dynamic")), is(ColumnPolicy.DYNAMIC)); sourceMap = getSourceMap(new PartitionName( new RelationName("doc", "dynamic_table"), Arrays.asList("3.0")).asIndexName()); assertThat(decodeMappingValue(sourceMap.get("dynamic")), is(ColumnPolicy.DYNAMIC)); }
Example #19
Source File: ColumnPolicyIntegrationTest.java From crate with Apache License 2.0 | 4 votes |
@Test public void testDynamicPartitionedTable() throws Exception { execute("create table numbers (" + " num int, " + " odd boolean," + " prime boolean" + ") partitioned by (odd) with (column_policy='dynamic', number_of_replicas=0)"); ensureYellow(); GetIndexTemplatesResponse templateResponse = client().admin().indices() .prepareGetTemplates(PartitionName.templateName(sqlExecutor.getCurrentSchema(), "numbers")) .execute().actionGet(); assertThat(templateResponse.getIndexTemplates().size(), is(1)); IndexTemplateMetaData template = templateResponse.getIndexTemplates().get(0); CompressedXContent mappingStr = template.mappings().get(Constants.DEFAULT_MAPPING_TYPE); assertThat(mappingStr, is(notNullValue())); Tuple<XContentType, Map<String, Object>> typeAndMap = XContentHelper.convertToMap(mappingStr.compressedReference(), false); @SuppressWarnings("unchecked") Map<String, Object> mapping = (Map<String, Object>) typeAndMap.v2().get(Constants.DEFAULT_MAPPING_TYPE); assertThat(String.valueOf(mapping.get("dynamic")), is("true")); execute("insert into numbers (num, odd, prime) values (?, ?, ?)", new Object[]{6, true, false}); execute("refresh table numbers"); Map<String, Object> sourceMap = getSourceMap( new PartitionName(new RelationName("doc", "numbers"), Collections.singletonList("true")).asIndexName()); assertThat(String.valueOf(sourceMap.get("dynamic")), is("true")); execute("insert into numbers (num, odd, prime, perfect) values (?, ?, ?, ?)", new Object[]{28, true, false, true}); ensureYellow(); execute("refresh table numbers"); waitForMappingUpdateOnAll("numbers", "perfect"); execute("select * from numbers order by num"); assertThat(response.rowCount(), is(2L)); assertThat(response.cols(), arrayContaining("num", "odd", "prime", "perfect")); assertThat(TestingHelpers.printedTable(response.rows()), is( "6| true| false| NULL\n" + "28| true| false| true\n")); execute("update numbers set prime=true, changed='2014-10-23T10:20', author='troll' where num=28"); assertThat(response.rowCount(), is(1L)); waitForMappingUpdateOnAll("numbers", "changed"); }
Example #20
Source File: AbstractESTest.java From elasticsearch-migration with Apache License 2.0 | 4 votes |
@SneakyThrows protected boolean checkTemplateExists(String name) { final ActionFuture<GetIndexTemplatesResponse> response = client.admin().indices().getTemplates(new GetIndexTemplatesRequest(name)); return !response.get().getIndexTemplates().isEmpty(); }
Example #21
Source File: PartitionedTableIntegrationTest.java From crate with Apache License 2.0 | 4 votes |
@Test public void testAlterNumberOfReplicas() { String defaultSchema = sqlExecutor.getCurrentSchema(); execute( "create table quotes (" + " id integer," + " quote string," + " date timestamp with time zone" + ") partitioned by(date) " + "clustered into 3 shards with (number_of_replicas='0-all')"); ensureYellow(); String templateName = PartitionName.templateName(defaultSchema, "quotes"); GetIndexTemplatesResponse templatesResponse = client().admin().indices() .prepareGetTemplates(templateName).execute().actionGet(); Settings templateSettings = templatesResponse.getIndexTemplates().get(0).getSettings(); assertThat(templateSettings.get(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS), is("0-all")); execute("alter table quotes set (number_of_replicas=0)"); ensureYellow(); templatesResponse = client().admin().indices() .prepareGetTemplates(templateName).execute().actionGet(); templateSettings = templatesResponse.getIndexTemplates().get(0).getSettings(); assertThat(templateSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1), is(0)); assertThat(templateSettings.getAsBoolean(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS, true), is(false)); execute("insert into quotes (id, quote, date) values (?, ?, ?), (?, ?, ?)", new Object[]{1, "Don't panic", 1395874800000L, 2, "Now panic", 1395961200000L} ); assertThat(response.rowCount(), is(2L)); ensureYellow(); refresh(); assertTrue(clusterService().state().metaData().hasAlias(getFqn("quotes"))); List<String> partitions = ImmutableList.of( new PartitionName( new RelationName(defaultSchema, "quotes"), Collections.singletonList("1395874800000")).asIndexName(), new PartitionName( new RelationName(defaultSchema, "quotes"), Collections.singletonList("1395961200000")).asIndexName() ); execute("select number_of_replicas from information_schema.table_partitions"); assertThat( printedTable(response.rows()), is("0\n" + "0\n")); execute("select number_of_replicas, number_of_shards from information_schema.tables where table_name = 'quotes'"); assertEquals("0", response.rows()[0][0]); assertEquals(3, response.rows()[0][1]); execute("alter table quotes set (number_of_replicas='1-all')"); ensureYellow(); execute("select number_of_replicas from information_schema.tables where table_name = 'quotes'"); assertEquals("1-all", response.rows()[0][0]); templatesResponse = client().admin().indices() .prepareGetTemplates(templateName).execute().actionGet(); templateSettings = templatesResponse.getIndexTemplates().get(0).getSettings(); assertThat(templateSettings.get(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS), is("1-all")); execute("select number_of_replicas from information_schema.table_partitions"); assertThat( printedTable(response.rows()), is("1-all\n" + "1-all\n")); }
Example #22
Source File: AbstractClient.java From crate with Apache License 2.0 | 4 votes |
@Override public void getTemplates(final GetIndexTemplatesRequest request, final ActionListener<GetIndexTemplatesResponse> listener) { execute(GetIndexTemplatesAction.INSTANCE, request, listener); }
Example #23
Source File: AbstractClient.java From crate with Apache License 2.0 | 4 votes |
@Override public ActionFuture<GetIndexTemplatesResponse> getTemplates(final GetIndexTemplatesRequest request) { return execute(GetIndexTemplatesAction.INSTANCE, request); }
Example #24
Source File: AbstractClient.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public void getTemplates(final GetIndexTemplatesRequest request, final ActionListener<GetIndexTemplatesResponse> listener) { execute(GetIndexTemplatesAction.INSTANCE, request, listener); }
Example #25
Source File: AbstractClient.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public ActionFuture<GetIndexTemplatesResponse> getTemplates(final GetIndexTemplatesRequest request) { return execute(GetIndexTemplatesAction.INSTANCE, request); }
Example #26
Source File: IndicesAdminClient.java From crate with Apache License 2.0 | 2 votes |
/** * Gets an index template. */ void getTemplates(GetIndexTemplatesRequest request, ActionListener<GetIndexTemplatesResponse> listener);
Example #27
Source File: IndicesAdminClient.java From crate with Apache License 2.0 | 2 votes |
/** * Gets index template. */ ActionFuture<GetIndexTemplatesResponse> getTemplates(GetIndexTemplatesRequest request);
Example #28
Source File: IndicesAdminClient.java From Elasticsearch with Apache License 2.0 | 2 votes |
/** * Gets an index template. */ void getTemplates(GetIndexTemplatesRequest request, ActionListener<GetIndexTemplatesResponse> listener);
Example #29
Source File: IndicesAdminClient.java From Elasticsearch with Apache License 2.0 | 2 votes |
/** * Gets index template. */ ActionFuture<GetIndexTemplatesResponse> getTemplates(GetIndexTemplatesRequest request);