index_.asciidoc 895 B

12345678910111213141516171819202122232425262728293031
  1. [[index_]]
  2. == Index API
  3. The index API is very similar to the
  4. {java}/index_.html[Java index API]. The Groovy
  5. extension to it is the ability to provide the indexed source using a
  6. closure. For example:
  7. [source,js]
  8. --------------------------------------------------
  9. def indexR = client.index {
  10. index "test"
  11. type "type1"
  12. id "1"
  13. source {
  14. test = "value"
  15. complex {
  16. value1 = "value1"
  17. value2 = "value2"
  18. }
  19. }
  20. }
  21. --------------------------------------------------
  22. In the above example, the source closure itself gets transformed into an
  23. XContent (defaults to JSON). In order to change how the source closure
  24. is serialized, a global (static) setting can be set on the `GClient` by
  25. changing the `indexContentType` field.
  26. Note also that the `source` can be set using the typical Java based
  27. APIs, the `Closure` option is a Groovy extension.