put-mapping.asciidoc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. [[java-admin-indices-put-mapping]]
  2. ==== Put Mapping
  3. The PUT mapping API allows you to add a new type while creating an index:
  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> It also adds a `tweet` mapping type.
  10. The PUT mapping API also allows to add a new type to an existing index:
  11. ["source","java",subs="attributes,callouts,macros"]
  12. --------------------------------------------------
  13. include-tagged::{client-tests}/IndicesDocumentationIT.java[putMapping-request-source]
  14. --------------------------------------------------
  15. <1> Puts a mapping on existing index called `twitter`
  16. <2> Adds a `user` mapping type.
  17. <3> This `user` has a predefined type
  18. <4> type can be also provided within the source
  19. You can use the same API to update an existing mapping:
  20. ["source","java",subs="attributes,callouts,macros"]
  21. --------------------------------------------------
  22. include-tagged::{client-tests}/IndicesDocumentationIT.java[putMapping-request-source-append]
  23. --------------------------------------------------
  24. <1> Puts a mapping on existing index called `twitter`
  25. <2> Updates the `user` mapping type.
  26. <3> This `user` has now a new field `user_name`
  27. :base-dir!: