OpenSearch/docs/groovy-api/index_.asciidoc
Julie Tibshirani f854330e06
Make sure to use the type _doc in the REST documentation. (#34662)
* Replace custom type names with _doc in REST examples.
* Avoid using two mapping types in the percolator docs.
* Rename doc -> _doc in the main repository README.
* Also replace some custom type names in the HLRC docs.
2018-10-22 11:54:04 -07:00

33 lines
917 B
Plaintext

[[index_]]
== Index API
The index API is very similar to the
// {javaclient}/java-docs-index.html[]
Java index API. The Groovy
extension to it is the ability to provide the indexed source using a
closure. For example:
[source,groovy]
--------------------------------------------------
def indexR = client.index {
index "test"
type "_doc"
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.