"Fossies" - the Fresh Open Source Software Archive

Member "elasticsearch-6.8.23/docs/groovy-api/client.asciidoc" (29 Dec 2021, 1444 Bytes) of package /linux/www/elasticsearch-6.8.23-src.tar.gz:

As a special service "Fossies" has tried to format the requested source page into HTML format (assuming AsciiDoc format). Alternatively you can here view or download the uninterpreted source code file. A member file download can also be achieved by clicking within a package contents listing on the according byte size field.


Obtaining an Elasticsearch Groovy GClient (a GClient is a simple wrapper on top of the Java Client) is simple. The most common way to get a client is by starting an embedded Node which acts as a node within the cluster.

Node Client

A Node based client is the simplest form to get a GClient to start executing operations against Elasticsearch.

import org.elasticsearch.groovy.client.GClient
import org.elasticsearch.groovy.node.GNode
import static org.elasticsearch.groovy.node.GNodeBuilder.nodeBuilder

// on startup

GNode node = nodeBuilder().node();
GClient client = node.client();

// on shutdown


Since Elasticsearch allows to configure it using JSON based settings, the configuration itself can be done using a closure that represent the JSON:

import org.elasticsearch.groovy.node.GNode
import org.elasticsearch.groovy.node.GNodeBuilder
import static org.elasticsearch.groovy.node.GNodeBuilder.*

// on startup

GNodeBuilder nodeBuilder = nodeBuilder();
nodeBuilder.settings {
    node {
        client = true
    cluster {
        name = "test"

GNode node = nodeBuilder.node()

// on shutdown