コード例 #1
0
 public Builder(IndexTemplateMetaData indexTemplateMetaData) {
   this(indexTemplateMetaData.name());
   order(indexTemplateMetaData.order());
   template(indexTemplateMetaData.template());
   settings(indexTemplateMetaData.settings());
   mappings.putAll(indexTemplateMetaData.mappings());
 }
コード例 #2
0
    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();
    }
コード例 #3
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();
  }
コード例 #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();
 }
コード例 #5
0
  @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*");
  }
コード例 #6
0
 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);
   }
 }
コード例 #7
0
 @Override
 public boolean apply(
     CreateIndexClusterStateUpdateRequest request, IndexTemplateMetaData template) {
   return Regex.simpleMatch(template.template(), request.index());
 }
コード例 #8
0
 public Builder put(IndexTemplateMetaData template) {
   templates.put(template.name(), template);
   return this;
 }