public Builder(IndexTemplateMetaData indexTemplateMetaData) {
   this(indexTemplateMetaData.name());
   order(indexTemplateMetaData.order());
   template(indexTemplateMetaData.template());
   settings(indexTemplateMetaData.settings());
   mappings.putAll(indexTemplateMetaData.mappings());
 }
    public static void toXContent(
        IndexTemplateMetaData indexTemplateMetaData,
        XContentBuilder builder,
        ToXContent.Params params)
        throws IOException {
      builder.startObject(indexTemplateMetaData.name(), XContentBuilder.FieldCaseConversion.NONE);

      builder.field("order", indexTemplateMetaData.order());
      builder.field("template", indexTemplateMetaData.template());

      builder.startObject("settings");
      for (Map.Entry<String, String> entry :
          indexTemplateMetaData.settings().getAsMap().entrySet()) {
        builder.field(entry.getKey(), entry.getValue());
      }
      builder.endObject();

      builder.startArray("mappings");
      for (Map.Entry<String, CompressedString> entry :
          indexTemplateMetaData.mappings().entrySet()) {
        byte[] data = entry.getValue().uncompressed();
        XContentParser parser = XContentFactory.xContent(data).createParser(data);
        Map<String, Object> mapping = parser.map();
        parser.close();
        builder.map(mapping);
      }
      builder.endArray();

      builder.endObject();
    }
  @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();
  }
Esempio n. 4
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();
 }
  @Test
  public void testThatTemplateIsNotOverWritten() throws Exception {
    client()
        .admin()
        .indices()
        .preparePutTemplate("metrics_template")
        .setTemplate("foo*")
        .setSettings("{ \"index.number_of_shards\" : \"1\"}")
        .execute()
        .actionGet();

    elasticsearchReporter = createElasticsearchReporterBuilder().build();

    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.template()).isEqualTo("foo*");
  }
 public static void writeTo(IndexTemplateMetaData indexTemplateMetaData, StreamOutput out)
     throws IOException {
   out.writeUTF(indexTemplateMetaData.name());
   out.writeInt(indexTemplateMetaData.order());
   out.writeUTF(indexTemplateMetaData.template());
   ImmutableSettings.writeSettingsToStream(indexTemplateMetaData.settings(), out);
   out.writeVInt(indexTemplateMetaData.mappings().size());
   for (Map.Entry<String, CompressedString> entry :
       indexTemplateMetaData.mappings().entrySet()) {
     out.writeUTF(entry.getKey());
     entry.getValue().writeTo(out);
   }
 }
 @Override
 public boolean apply(
     CreateIndexClusterStateUpdateRequest request, IndexTemplateMetaData template) {
   return Regex.simpleMatch(template.template(), request.index());
 }
Esempio n. 8
0
 public Builder put(IndexTemplateMetaData template) {
   templates.put(template.name(), template);
   return this;
 }