put-mapping.asciidoc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. [[java-admin-indices-put-mapping]]
  2. :base-dir: {docdir}/../../server/src/test/java/org/elasticsearch/action/admin/indices/create
  3. ==== Put Mapping
  4. The PUT mapping API allows you to add a new type while creating an index:
  5. ["source","java",subs="attributes,callouts,macros"]
  6. --------------------------------------------------
  7. include-tagged::{base-dir}/CreateIndexIT.java[addMapping-create-index-request]
  8. --------------------------------------------------
  9. <1> <<java-admin-indices-create-index,Creates an index>> called `twitter`
  10. <2> It also adds a `tweet` mapping type.
  11. The PUT mapping API also allows to add a new type to an existing index:
  12. ["source","java",subs="attributes,callouts,macros"]
  13. --------------------------------------------------
  14. include-tagged::{base-dir}/CreateIndexIT.java[putMapping-request-source]
  15. --------------------------------------------------
  16. <1> Puts a mapping on existing index called `twitter`
  17. <2> Adds a `user` mapping type.
  18. <3> This `user` has a predefined type
  19. <4> type can be also provided within the source
  20. You can use the same API to update an existing mapping:
  21. ["source","java",subs="attributes,callouts,macros"]
  22. --------------------------------------------------
  23. include-tagged::{base-dir}/CreateIndexIT.java[putMapping-request-source-append]
  24. --------------------------------------------------
  25. <1> Puts a mapping on existing index called `twitter`
  26. <2> Updates the `user` mapping type.
  27. <3> This `user` has now a new field `user_name`
  28. :base-dir!: