index_.asciidoc 917 B

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