title: Spring Data Elasticsearch doesn't implicitly create mapping from annotations
body: <p>I'm trying to work with Spring Data Elasticsearch 4.0.1 and trying to figure out how and when the Elasticsearch mappings are being created by Spring or if they are being created by Spring.</p>
  <p>If I have an entity like so:</p>
  <pre><code>@Document(indexName = &quot;companies&quot;)
  public class CompanyEntity {
  
    @Id
    private final String id;
  
    @MultiField(
        mainField = @Field(type = Text),
        otherFields = {
            @InnerField(suffix = &quot;raw&quot;, type = Keyword)
        }
    )
    private final String companyName;
  
    @PersistenceConstructor
    public CompanyEntity(String id, String companyName) {
      this.id = id;
      this.companyName = companyName;
    }
  
    public String getId() {
      return id;
    }
  
    public String getCompanyName() {
      return companyName;
    }
  }
  </code></pre>
  <p>I was under the impression that Spring would implicitly create the mapping for this index but I seem to be mistaken.  Elasticsearch still creates the mapping for this index.</p>
  <pre><code>{
      &quot;companies&quot;: {
          &quot;mappings&quot;: {
              &quot;properties&quot;: {
                  &quot;_class&quot;: {
                      &quot;type&quot;: &quot;text&quot;,
                      &quot;fields&quot;: {
                          &quot;keyword&quot;: {
                              &quot;type&quot;: &quot;keyword&quot;,
                              &quot;ignore_above&quot;: 256
                          }
                      }
                  },
                  &quot;companyName&quot;: {
                      &quot;type&quot;: &quot;text&quot;,
                      &quot;fields&quot;: {
                          &quot;keyword&quot;: {
                              &quot;type&quot;: &quot;keyword&quot;,
                              &quot;ignore_above&quot;: 256
                          }
                      }
                  },
                  &quot;id&quot;: {
                      &quot;type&quot;: &quot;text&quot;,
                      &quot;fields&quot;: {
                          &quot;keyword&quot;: {
                              &quot;type&quot;: &quot;keyword&quot;,
                              &quot;ignore_above&quot;: 256
                          }
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  <p>Clearly from the above, the suffix in the InnerField annotation is not used and the ignore_above value is not used as well since it defaults to -1, and Elasticsearch would remove this field altogether if trying to set ignore_above to -1.</p>
  <p>The only way I was able to get the mapping for the above annotations was to explicitly set the mapping myself.</p>
  <pre><code>@Autowired private ElasticsearchOperations operations;
  
  Document mapping = operations.indexOps(CompanyEntity.class).createMapping();
  operations.indexOps(CompanyEntity.class).putMapping(mapping); 
  </code></pre>
  <p>Which yields the expected mapping:</p>
  <pre><code>{
      &quot;companies&quot;: {
          &quot;mappings&quot;: {
              &quot;properties&quot;: {
                  &quot;_class&quot;: {
                      &quot;type&quot;: &quot;text&quot;,
                      &quot;fields&quot;: {
                          &quot;keyword&quot;: {
                              &quot;type&quot;: &quot;keyword&quot;,
                              &quot;ignore_above&quot;: 256
                          }
                      }
                  },
                  &quot;companyName&quot;: {
                      &quot;type&quot;: &quot;text&quot;,
                      &quot;fields&quot;: {
                          &quot;raw&quot;: {
                              &quot;type&quot;: &quot;keyword&quot;
                          }
                      }
                  },
                  &quot;id&quot;: {
                      &quot;type&quot;: &quot;text&quot;,
                      &quot;fields&quot;: {
                          &quot;keyword&quot;: {
                              &quot;type&quot;: &quot;keyword&quot;,
                              &quot;ignore_above&quot;: 256
                          }
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  <p>Which is fine, but feels a bit odd to me as I could not find any details of this approach in the official <a href="https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#elasticsearch.mapping" rel="nofollow noreferrer">Spring Data Elasticsearch docs</a>.  And the JavaDocs are kinda void of any details.</p>
  <p>Is this the right approach to installing mappings into Elasticsearch from Spring Data?</p>