• This repository has been archived on 10/Sep/2019
  • Stars
    star
    37
  • Rank 720,807 (Top 15 %)
  • Language
    Groovy
  • License
    Apache License 2.0
  • Created almost 11 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Elasticsearch Groovy client

Groovy Client for Elasticsearch

IMPORTANT: The Groovy Client is deprecated as of Elasticsearch v6.0.0 and is no longer actively maintained.

The Elasticsearch Groovy client project helps you to use Elasticsearch in Groovy projects. This Groovy client inherently supports 100% of the Elasticsearch API for the supported version by using Groovy extension modules with the Java client. Literally anything possible in the same version of the Java client is possible with the Groovy client, plus some Groovy-friendly extensions.

You can use the Java client code from any Java client example that you find online with the benefit of the Groovy extensions.

TransportClient client = TransportClient.builder().settings(Settings.settingsBuilder {
  client.transport.sniff = true
  cluster.name = "your-cluster-name"
}).build()

// identical to the Java client:
client.addTransportAddress( ... )

String userId = "some-user-id"

// asynchronously fetch the results
ListenableActionFuture<SearchResponse> future = client.searchAsync {
  indices "your-index"
  types "your-type"
  source {
    query {
      match {
        user.id = userId
      }
    }
  }
}

// block until the response is retrieved (you could alternatively use listeners)
SearchResponse response = future.actionGet()

Besides the usage of Closures, the above example should look very familiar to any existing Java client users, as well as those familiar with the Elasticsearch DSL (Domain Specific Language used for indexing and querying).

Versions

You need to install a version matching your Elasticsearch version:

Elasticsearch Groovy Client Java Groovy
master [5.0] Build from source [5.0] 8 or later 2.4.5
2.1 - 2.4 2.1 7u60 or later 2.4.4
2.0 2.0 7u60 or later 2.4.4
1.7 1.7 7u60 or later 2.4.4
1.6 1.6 7u60 or later 2.4.4
1.5 1.5 7u60 or later 2.4.1*
1.4 1.4 7u60 or later 2.3.7*

Please read documentation relative to the version that you are using!

To build a SNAPSHOT version, you need to build it with Gradle (see below for further details):

$ gradle clean installDist

Groovy Warning

Groovy released Groovy 2.4.4 to fix a vulnerability with CVE-2015-3253.

You are considered vulnerable just by having an earlier version of Groovy on your classpath! All users should upgrade to Groovy 2.4.4, or later, as a result.

JVM Warning

Both Elasticsearch and the Elasticsearch Groovy client require at least Java 7. In addition, the Groovy client is compiled with indy support enabled, which means that it theoretically could cause issues if you are running with Java 7u22 to 7u55 due to a bug in the JVM related to invokedynamic. This is reported directly from the Groovy developers and it is strongly suggested that you run Java 7u60 or later.

JVM Release Groovy Client Support invokedynamic Support
Java 5 Unsupported None
Java 6 Unsupported None
Java 7u22 to 7u55 Unsupported Buggy
Java 7u60 or later Supported [1.x, 2.x] Supported
Java 8 Supported [1.x or later] Supported

Groovy is supported on any JDK supported by Elasticsearch, which currently includes Oracle JDK and OpenJDK.

Adding to your Groovy projects

Gradle

repositories {
  mavenCentral()
}

dependencies {
  compile 'org.elasticsearch:elasticsearch-groovy:2.1.2'
}

Maven

<dependencies>
  <dependency>
    <groupId>org.elasticsearch</groupId>
    <artifactId>elasticsearch-groovy</artifactId>
    <version>2.1.2</version>
    <scope>compile</scope>
  </dependency>
</dependencies>

Grails 2.x

Out-of-the-box support for Grails is limited to Grails 2.4.4 or later. To use with earlier versions, you must follow the instructions found in GRAILS-10652 to load Groovy extension modules.

repositories {
  mavenCentral()
}

dependencies {
  // You may be able to use the 'runtime' scope
  compile group: 'org.elasticsearch', name: 'elasticsearch-groovy', version: '2.1.2', classifier: 'grails'
}

Grails 3.x has overhauled their build system to use Gradle, which makes it easy for you to select the version of Groovy to use with it, including the use of invokedynamic. However, Grails 2.x did not make it easy. A part of not being easy, Grails 2.x does not use the invokedynamic-compatible Groovy jar, which means that any Grails 2.x project requires a jar that is not compiled with invokedynamic.

With the release of Elasticsearch Groovy 1.4.3, we have introduced a secondary jar with a new grails classifier that can be used by Grails users. All other users are strongly recommended to use the invokedynamic-compatible versions described above (it's both faster and slightly smaller!).

Support for this is intended to assist the Grails community to use the Elasticsearch Groovy client prior to the release of Grails 3.0. If you are using Grails 3.0 or later, then you should use the invokedynamic version of Groovy and the Gradle dependency above.

Compiling Groovy Client

To compile this code on your own, then run:

$ gradle clean installDist

This will skip all tests and place the compiled jar in ./build/install/elasticsearch-groovy/elasticsearch-groovy-{version}.jar. It will package all dependencies (e.g., elasticsearch-{version}.jar) into ./build/install/elasticsearch-groovy/lib.

Testing Groovy Client

The Groovy client makes use of the Randomized Testing framework used by Elasticsearch itself. The unit tests and integration tests that this uses can be invoked with the same command:

$ gradle clean test

The various tests.* and es.* system properties that are used by Elasticsearch are also used by the Gradle build script. As a result, any recommendation that suggests running mvn clean test -DsystemProp=xyz can be replaced with gradle clean test -DsystemProp=xyz (the only change was from mvn to gradle). This only applies to the Groovy client.

Testing with IntelliJ

By default, IntelliJ will place all of the compile-time dependencies above the testCompile dependencies. In the case of the test frameworks used, this presents issues that occasionally trigger test failures (that tell you to fix your classpath with respect to "test-framework.jar"). To fix this behavior, put your test dependencies above any non-test dependencies within IntelliJ.

  1. Open Project Structure
  2. Select Modules

Suggested Groovy Settings

Since the release of Java 7 (aka Java 1.7), higher level languages like Groovy have had access to the invokedynamic JVM instruction. This avoids the need for some runtime code generation (e.g., $callSiteArrays) and it theoretically speeds up all Groovy code. In the Groovy world, there is still support for Java 5 and Java 6, which means that invokedynamic cannot be enabled by default.

Compiling Groovy with invokedynamic support

To support invokedynamic in your own Groovy project(s), at a minimum, you must include the invokedynamic-compiled Groovy jar, which the Groovy developers call the indy (invokedynamic) jar.

Gradle

repositories {
  mavenCentral()
}

dependencies {
  compile 'org.codehaus.groovy:groovy-all:2.4.5:indy'
}

Maven

<dependencies>
  <dependency>
    <groupId>org.codehaus.groovy</groupId>
    <artifactId>groovy-all</artifactId>
    <version>2.4.5</version>
    <classifier>indy</classifier>
    <scope>compile</scope>
  </dependency>
</dependencies>

Using invokedynamic in your Groovy code

After including the indy jar, you now only have an invokedynamic-compatible Groovy runtime. All internal Groovy calls will use invokedynamic, as will any other Groovy code compiled with invokedynamic support (e.g., the Groovy client), but your code must also be compiled with invokedynamic support to gain the benefits within your compiled jar(s).

Gradle

apply plugin: 'groovy'

// ...

/**
 * Customize Groovy compilation.
 */
tasks.withType(GroovyCompile) {
  groovyOptions.optimizationOptions.indy = true
}

Maven

Maven has numerous ways to do this, and it largely depends on how you compile your Groovy code. If you are wrapping the Ant task, then add indy="true" to the Groovy compilation. Otherwise check your plugin's documentation.

IntelliJ

When allowing IntelliJ to control the compilation of your project, then you must enable Invoke dynamic support within the preferences for the Groovy Compiler.

To change this setting:

  1. Open Preferences
  2. Select Compiler
  3. Select Groovy Compiler
  4. Check Invoke dynamic support

With IntelliJ 13, I have noticed that it is sometimes necessary to manually rebuild the project because it loses track of the resource files. This happens infrequently, but it will cause practically every test to fail when it does happen.

License

This software is licensed under the Apache 2 license, quoted below.

Copyright 2009-2015 Elastic <http://www.elastic.co>

Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.

More Repositories

1

elasticsearch

Free and Open, Distributed, RESTful Search Engine
Java
65,029
star
2

kibana

Your window into the Elastic Stack
TypeScript
19,520
star
3

logstash

Logstash - transport and process your logs, events, or other data
Java
13,615
star
4

elasticsearch-php

Official PHP client for Elasticsearch.
PHP
5,190
star
5

elasticsearch-js

Official Elasticsearch client library for Node.js
TypeScript
5,174
star
6

go-elasticsearch

The official Go client for Elasticsearch
Go
4,933
star
7

elasticsearch-py

Official Python client for Elasticsearch
Python
4,034
star
8

elasticsearch-dsl-py

High level Python client for Elasticsearch
Python
3,695
star
9

elasticsearch-definitive-guide

The Definitive Guide to Elasticsearch
HTML
3,521
star
10

elasticsearch-net

This strongly-typed, client library enables working with Elasticsearch. It is the official client maintained and supported by Elastic.
C#
3,469
star
11

curator

Curator: Tending your Elasticsearch indices
Python
3,032
star
12

elasticsearch-rails

Elasticsearch integrations for ActiveModel/Record and Ruby on Rails
Ruby
3,017
star
13

examples

Home for Elasticsearch examples available to everyone. It's a great way to get started.
Jupyter Notebook
2,587
star
14

cloud-on-k8s

Elastic Cloud on Kubernetes
Go
2,574
star
15

elasticsearch-ruby

Ruby integrations for Elasticsearch
Ruby
1,928
star
16

elasticsearch-hadoop

🐘 Elasticsearch real-time search and analytics natively integrated with Hadoop
Java
1,915
star
17

detection-rules

Python
1,884
star
18

helm-charts

You know, for Kubernetes
Python
1,807
star
19

search-ui

Search UI. Libraries for the fast development of modern, engaging search experiences.
TypeScript
1,796
star
20

logstash-forwarder

An experiment to cut logs in preparation for processing elsewhere. Replaced by Filebeat: https://github.com/elastic/beats/tree/master/filebeat
Go
1,788
star
21

ansible-elasticsearch

Ansible playbook for Elasticsearch
Ruby
1,567
star
22

stack-docker

Project no longer maintained.
Shell
1,189
star
23

apm-server

APM Server
Go
1,100
star
24

protections-artifacts

Elastic Security detection content for Endpoint
YARA
980
star
25

ecs

Elastic Common Schema
Python
920
star
26

ember

Elastic Malware Benchmark for Empowering Researchers
Jupyter Notebook
799
star
27

elasticsearch-docker

Official Elasticsearch Docker image
Python
790
star
28

elasticsearch-rs

Official Elasticsearch Rust Client
Rust
612
star
29

elasticsearch-labs

Notebooks & Example Apps for Search & AI Applications with Elasticsearch
Jupyter Notebook
597
star
30

elasticsearch-cloud-aws

AWS Cloud Plugin for Elasticsearch
580
star
31

apm-agent-nodejs

Elastic APM Node.js Agent
JavaScript
540
star
32

apm-agent-dotnet

Elastic APM .NET Agent
C#
540
star
33

apm-agent-java

Elastic APM Java Agent
Java
536
star
34

eland

Python Client and Toolkit for DataFrames, Big Data, Machine Learning and ETL in Elasticsearch
Python
516
star
35

elasticsearch-mapper-attachments

Mapper Attachments Type plugin for Elasticsearch
Java
503
star
36

elasticsearch-servicewrapper

A service wrapper on top of elasticsearch
Shell
489
star
37

apm-agent-go

Official Go agent for Elastic APM
Go
390
star
38

sense

A JSON aware developer's interface to Elasticsearch. Comes with handy machinery such as syntax highlighting, autocomplete, formatting and code folding.
JavaScript
382
star
39

apm-agent-python

Official Python agent for Elastic APM
Python
381
star
40

elastic-charts

TypeScript
365
star
41

stream2es

Stream data into ES (Wikipedia, Twitter, stdin, or other ESes)
Clojure
356
star
42

timelion

Timelion was absorbed into Kibana 5. Don't use this. Time series composer for Elasticsearch and beyond.
JavaScript
347
star
43

apm

Elastic Application Performance Monitoring - resources and general issue tracking for Elastic APM.
Gherkin
317
star
44

elasticsearch-net-example

A tutorial repository for Elasticsearch and NEST
305
star
45

elasticsearch-migration

This plugin will help you to check whether you can upgrade directly to the next major version of Elasticsearch, or whether you need to make changes to your data and cluster before doing so.
291
star
46

logstash-docker

Official Logstash Docker image
Python
286
star
47

elasticsearch-py-async

Backend for elasticsearch-py based on python's asyncio module.
Python
283
star
48

support-diagnostics

Support diagnostics utility for elasticsearch and logstash
Java
278
star
49

elasticsearch-java

Official Elasticsearch Java Client
Java
274
star
50

es2unix

Command-line ES
Clojure
274
star
51

elasticsearch-analysis-smartcn

Smart Chinese Analysis Plugin for Elasticsearch
268
star
52

dockerfiles

Dockerfiles for the official Elastic Stack images
Shell
253
star
53

go-sysinfo

go-sysinfo is a library for collecting system information.
Go
249
star
54

kibana-docker

Official Kibana Docker image
Python
243
star
55

elasticsearch-metrics-reporter-java

Metrics reporter, which reports to elasticsearch
Java
232
star
56

apm-agent-php

Elastic APM PHP Agent
PHP
229
star
57

docs

Ruby
229
star
58

elasticsearch-river-twitter

Twitter River Plugin for elasticsearch (STOPPED)
Java
202
star
59

elasticsearch-formal-models

Formal models of core Elasticsearch algorithms
Isabelle
200
star
60

rally-tracks

Track specifications for the Elasticsearch benchmarking tool Rally
Python
197
star
61

integrations

Elastic Integrations
Handlebars
194
star
62

beats-dashboards

DEPRECATED. Moved to https://github.com/elastic/beats. Please use the new repository to add new issues.
Shell
192
star
63

elasticsearch-analysis-icu

ICU Analysis plugin for Elasticsearch
189
star
64

elasticsearch-river-rabbitmq

RabbitMQ River Plugin for elasticsearch (STOPPED)
Java
173
star
65

terraform-provider-ec

Go
171
star
66

elasticsearch-analysis-kuromoji

Japanese (kuromoji) Analysis Plugin
168
star
67

dorothy

Dorothy is a tool to test security monitoring and detection for Okta environments
Python
167
star
68

beats-docker

Official Beats Docker images
Python
165
star
69

elasticsearch-river-couchdb

CouchDB River Plugin for elasticsearch (STOPPED)
Java
163
star
70

SWAT

Simple Workspace Attack Tool (SWAT) is a tool for simulating malicious behavior against Google Workspace in reference to the MITRE ATT&CK framework.
Python
156
star
71

apm-agent-ruby

Elastic APM agent for Ruby
Ruby
156
star
72

go-freelru

GC-less, fast and generic LRU hashmap library for Go
Go
151
star
73

require-in-the-middle

Module to hook into the Node.js require function
JavaScript
149
star
74

harp

Secret management by contract toolchain
Go
145
star
75

go-libaudit

go-libaudit is a library for communicating with the Linux Audit Framework.
Go
142
star
76

ml-cpp

Machine learning C++ code
C++
139
star
77

ecs-logging-java

Centralized logging for Java applications with the Elastic stack made easy
Java
137
star
78

ansible-beats

Ansible Beats Role
Ruby
131
star
79

logstash-contrib

THIS REPOSITORY IS NO LONGER USED.
Ruby
128
star
80

elasticsearch-analysis-phonetic

Phonetic Analysis Plugin for Elasticsearch
127
star
81

azure-marketplace

Elasticsearch Azure Marketplace offering + ARM template
Shell
122
star
82

golang-crossbuild

Shell
121
star
83

elastic-agent

Elastic Agent - single, unified way to add monitoring for logs, metrics, and other types of data to a host.
Go
121
star
84

anonymize-it

a general utility for anonymizing data
Python
117
star
85

bpfcov

Source-code based coverage for eBPF programs actually running in the Linux kernel
C
115
star
86

windows-installers

Windows installers for the Elastic stack
C#
113
star
87

terraform-provider-elasticstack

Terraform provider for Elastic Stack
Go
111
star
88

makelogs

JavaScript
108
star
89

elasticsearch-lang-python

Python language Plugin for elasticsearch
104
star
90

stack-docs

Elastic Stack Documentation
Java
96
star
91

sysgrok

LLM-driven assistant for analyzing, understanding and optimizing systems
Python
94
star
92

elasticsearch-lang-javascript

JavaScript language Plugin for elasticsearch
93
star
93

crawler

Ruby
92
star
94

elasticsearch-specification

Elasticsearch full specification
TypeScript
89
star
95

elasticsearch-perl

Official Perl low-level client for Elasticsearch.
Perl
87
star
96

next-eui-starter

Start building Kibana protoypes quickly with the Next.js EUI Starter
TypeScript
87
star
97

vue-search-ui-demo

A demo of implementing Elastic's Search UI and App Search using Vue.js
Vue
87
star
98

elasticsearch-transport-thrift

Thrift Transport for elasticsearch (STOPPED)
Java
84
star
99

beats

🐠 Beats - Lightweight shippers for Elasticsearch & Logstash
Go
83
star
100

ecs-dotnet

.NET integrations that use the Elastic Common Schema (ECS)
HTML
82
star