2013-08-28 19:24:34 -04:00
|
|
|
[[index_]]
|
|
|
|
== Index API
|
|
|
|
|
|
|
|
The index API is very similar to the
|
2017-02-04 05:42:45 -05:00
|
|
|
// {javaclient}/java-docs-index.html[]
|
2015-10-22 18:00:35 -04:00
|
|
|
Java index API. The Groovy
|
2013-08-28 19:24:34 -04:00
|
|
|
extension to it is the ability to provide the indexed source using a
|
|
|
|
closure. For example:
|
|
|
|
|
2016-08-29 17:33:25 -04:00
|
|
|
[source,groovy]
|
2013-08-28 19:24:34 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
def indexR = client.index {
|
|
|
|
index "test"
|
2018-10-22 14:54:04 -04:00
|
|
|
type "_doc"
|
2013-08-28 19:24:34 -04:00
|
|
|
id "1"
|
|
|
|
source {
|
|
|
|
test = "value"
|
|
|
|
complex {
|
|
|
|
value1 = "value1"
|
|
|
|
value2 = "value2"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
In the above example, the source closure itself gets transformed into an
|
|
|
|
XContent (defaults to JSON). In order to change how the source closure
|
|
|
|
is serialized, a global (static) setting can be set on the `GClient` by
|
|
|
|
changing the `indexContentType` field.
|
|
|
|
|
|
|
|
Note also that the `source` can be set using the typical Java based
|
|
|
|
APIs, the `Closure` option is a Groovy extension.
|