use of org.opensearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project OpenSearch by opensearch-project.
the class SimpleClusterStateIT method testIndexTemplates.
public void testIndexTemplates() throws Exception {
client().admin().indices().preparePutTemplate("foo_template").setPatterns(Collections.singletonList("te*")).setOrder(0).addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("field1").field("type", "text").field("store", true).endObject().startObject("field2").field("type", "keyword").field("store", true).endObject().endObject().endObject().endObject()).get();
client().admin().indices().preparePutTemplate("fuu_template").setPatterns(Collections.singletonList("test*")).setOrder(1).addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("field2").field("type", "text").field("store", false).endObject().endObject().endObject().endObject()).get();
ClusterStateResponse clusterStateResponseUnfiltered = client().admin().cluster().prepareState().get();
assertThat(clusterStateResponseUnfiltered.getState().metadata().templates().size(), is(greaterThanOrEqualTo(2)));
GetIndexTemplatesResponse getIndexTemplatesResponse = client().admin().indices().prepareGetTemplates("foo_template").get();
assertIndexTemplateExists(getIndexTemplatesResponse, "foo_template");
}
use of org.opensearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project OpenSearch by opensearch-project.
the class IndexTemplateBlocksIT method testIndexTemplatesWithBlocks.
public void testIndexTemplatesWithBlocks() throws IOException {
// creates a simple index template
client().admin().indices().preparePutTemplate("template_blocks").setPatterns(Collections.singletonList("te*")).setOrder(0).addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("field1").field("type", "text").field("store", true).endObject().startObject("field2").field("type", "keyword").field("store", true).endObject().endObject().endObject().endObject()).execute().actionGet();
try {
setClusterReadOnly(true);
GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates("template_blocks").execute().actionGet();
assertThat(response.getIndexTemplates(), hasSize(1));
assertBlocked(client().admin().indices().preparePutTemplate("template_blocks_2").setPatterns(Collections.singletonList("block*")).setOrder(0).addAlias(new Alias("alias_1")));
assertBlocked(client().admin().indices().prepareDeleteTemplate("template_blocks"));
} finally {
setClusterReadOnly(false);
}
}
use of org.opensearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project OpenSearch by opensearch-project.
the class SimpleIndexTemplateIT method testInvalidSettings.
public void testInvalidSettings() throws Exception {
// clean all templates setup by the framework.
client().admin().indices().prepareDeleteTemplate("*").get();
// check get all templates on an empty index.
GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates().get();
assertThat(response.getIndexTemplates(), empty());
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> client().admin().indices().preparePutTemplate("template_1").setPatterns(Collections.singletonList("te*")).setSettings(Settings.builder().put("does_not_exist", "test")).get());
assertEquals("unknown setting [index.does_not_exist] please check that any required plugins are" + " installed, or check the breaking changes documentation for removed settings", e.getMessage());
response = client().admin().indices().prepareGetTemplates().get();
assertEquals(0, response.getIndexTemplates().size());
createIndex("test");
GetSettingsResponse getSettingsResponse = client().admin().indices().prepareGetSettings("test").get();
assertNull(getSettingsResponse.getIndexToSettings().get("test").get("index.does_not_exist"));
}
use of org.opensearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project OpenSearch by opensearch-project.
the class SimpleIndexTemplateIT method testPartitionedTemplate.
public void testPartitionedTemplate() throws Exception {
// clean all templates setup by the framework.
client().admin().indices().prepareDeleteTemplate("*").get();
// check get all templates on an empty index.
GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates().get();
assertThat(response.getIndexTemplates(), empty());
// provide more partitions than shards
IllegalArgumentException eBadSettings = expectThrows(IllegalArgumentException.class, () -> client().admin().indices().preparePutTemplate("template_1").setPatterns(Collections.singletonList("te*")).setSettings(Settings.builder().put("index.number_of_shards", "5").put("index.routing_partition_size", "6")).get());
assertThat(eBadSettings.getMessage(), containsString("partition size [6] should be a positive number " + "less than the number of shards [5]"));
// provide an invalid mapping for a partitioned index
IllegalArgumentException eBadMapping = expectThrows(IllegalArgumentException.class, () -> client().admin().indices().preparePutTemplate("template_2").setPatterns(Collections.singletonList("te*")).addMapping("type", "{\"type\":{\"_routing\":{\"required\":false}}}", XContentType.JSON).setSettings(Settings.builder().put("index.number_of_shards", "6").put("index.routing_partition_size", "3")).get());
assertThat(eBadMapping.getMessage(), containsString("must have routing required for partitioned index"));
// no templates yet
response = client().admin().indices().prepareGetTemplates().get();
assertEquals(0, response.getIndexTemplates().size());
// a valid configuration that only provides the partition size
assertAcked(client().admin().indices().preparePutTemplate("just_partitions").setPatterns(Collections.singletonList("te*")).setSettings(Settings.builder().put("index.routing_partition_size", "6")).get());
// create an index with too few shards
IllegalArgumentException eBadIndex = expectThrows(IllegalArgumentException.class, () -> prepareCreate("test_bad", Settings.builder().put("index.number_of_shards", 5).put("index.number_of_routing_shards", 5)).get());
assertThat(eBadIndex.getMessage(), containsString("partition size [6] should be a positive number " + "less than the number of shards [5]"));
// finally, create a valid index
prepareCreate("test_good", Settings.builder().put("index.number_of_shards", 7).put("index.number_of_routing_shards", 7)).get();
GetSettingsResponse getSettingsResponse = client().admin().indices().prepareGetSettings("test_good").get();
assertEquals("6", getSettingsResponse.getIndexToSettings().get("test_good").get("index.routing_partition_size"));
}
use of org.opensearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project OpenSearch by opensearch-project.
the class SimpleIndexTemplateIT method testAliasInvalidFilterValidJson.
public void testAliasInvalidFilterValidJson() throws Exception {
// invalid filter but valid json: put index template works fine, fails during index creation
client().admin().indices().preparePutTemplate("template_1").setPatterns(Collections.singletonList("te*")).addAlias(new Alias("invalid_alias").filter("{ \"invalid\": {} }")).get();
GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates("template_1").get();
assertThat(response.getIndexTemplates().size(), equalTo(1));
assertThat(response.getIndexTemplates().get(0).getAliases().size(), equalTo(1));
assertThat(response.getIndexTemplates().get(0).getAliases().get("invalid_alias").filter().string(), equalTo("{\"invalid\":{}}"));
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> createIndex("test"));
assertThat(e.getMessage(), equalTo("failed to parse filter for alias [invalid_alias]"));
assertThat(e.getCause(), instanceOf(ParsingException.class));
assertThat(e.getCause().getMessage(), equalTo("unknown query [invalid]"));
}
Aggregations