コード例 #1
0
  @Test
  public void testThatTemplateIsAdded() throws Exception {
    GetIndexTemplatesResponse response =
        client().admin().indices().prepareGetTemplates("metrics_template").get();

    org.assertj.core.api.Assertions.assertThat(response.getIndexTemplates()).hasSize(1);
    IndexTemplateMetaData templateData = response.getIndexTemplates().get(0);
    org.assertj.core.api.Assertions.assertThat(templateData.order()).isEqualTo(0);
    org.assertj.core.api.Assertions.assertThat(templateData.getMappings().get("_default_"))
        .isNotNull();
  }
コード例 #2
0
 private DocIndexMetaData buildDocIndexMetaDataFromTemplate(String index, String templateName) {
   IndexTemplateMetaData indexTemplateMetaData = metaData.getTemplates().get(templateName);
   DocIndexMetaData docIndexMetaData;
   try {
     IndexMetaData.Builder builder = new IndexMetaData.Builder(index);
     builder.putMapping(
         Constants.DEFAULT_MAPPING_TYPE,
         indexTemplateMetaData.getMappings().get(Constants.DEFAULT_MAPPING_TYPE).toString());
     Settings settings = indexTemplateMetaData.settings();
     builder.settings(settings);
     // default values
     builder.numberOfShards(settings.getAsInt(SETTING_NUMBER_OF_SHARDS, 5));
     builder.numberOfReplicas(settings.getAsInt(SETTING_NUMBER_OF_REPLICAS, 1));
     docIndexMetaData = new DocIndexMetaData(functions, builder.build(), ident);
   } catch (IOException e) {
     throw new UnhandledServerException("Unable to build DocIndexMetaData from template", e);
   }
   return docIndexMetaData.build();
 }