put-mapping.asciidoc 1.3 KB

123456789101112131415161718192021222324252627282930
  1. [[java-admin-indices-put-mapping]]
  2. ==== Put Mapping
  3. You can add mappings at index creation time:
  4. ["source","java",subs="attributes,callouts,macros"]
  5. --------------------------------------------------
  6. include-tagged::{client-tests}/IndicesDocumentationIT.java[index-with-mapping]
  7. --------------------------------------------------
  8. <1> <<java-admin-indices-create-index,Creates an index>> called `twitter`
  9. <2> Add a `_doc` type with a field called `message` that has the datatype `text`.
  10. There are several variants of the above `addMapping` method, some taking an
  11. `XContentBuilder` or a `Map` with the mapping definition as arguments. Make sure
  12. to check the javadocs to pick the simplest one for your use case.
  13. The PUT mapping API also allows for updating the mapping after index
  14. creation. In this case you can provide the mapping as a String similar
  15. to the REST API syntax:
  16. ["source","java",subs="attributes,callouts,macros"]
  17. --------------------------------------------------
  18. include-tagged::{client-tests}/IndicesDocumentationIT.java[putMapping-request-source]
  19. --------------------------------------------------
  20. <1> Puts a mapping on existing index called `twitter`
  21. <2> Adds a new field `name` to the mapping
  22. <3> The type can be also provided within the source
  23. :base-dir!: