OpenSearch/docs/groovy-api/index_.asciidoc
Nik Everett 5cff2a046d Remove most of the need for // NOTCONSOLE
and be much more stingy about what we consider a console candidate.

* Add `// CONSOLE` to check-running
* Fix version in some snippets
* Mark groovy snippets as groovy
* Fix versions in plugins
* Fix language marker errors
* Fix language parsing in snippets

  This adds support for snippets who's language is written like
  `[source, txt]` and `["source","js",subs="attributes,callouts"]`.

  This also makes language required for snippets which is nice because
  then we can be sure we can grep for snippets in a particular language.
2016-09-06 10:32:54 -04:00

33 lines
912 B
Plaintext

[[index_]]
== Index API
The index API is very similar to the
// {java}/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 "type1"
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.