put-mapping.asciidoc 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. [[java-admin-indices-put-mapping]]
  2. ==== Put Mapping
  3. You can add mappings for a new type 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 `tweet` 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 to specify the mapping of a type after index
  14. creation. In this case you can provide the mapping as a String similar to the
  15. 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 `user` mapping type.
  22. <3> This `user` has a predefined type
  23. <4> type can be also provided within the source
  24. You can use the same API to update an existing mapping:
  25. ["source","java",subs="attributes,callouts,macros"]
  26. --------------------------------------------------
  27. include-tagged::{client-tests}/IndicesDocumentationIT.java[putMapping-request-source-append]
  28. --------------------------------------------------
  29. <1> Puts a mapping on existing index called `twitter`
  30. <2> Updates the `user` mapping type.
  31. <3> This `user` has now a new field `user_name`
  32. :base-dir!: