Elasticsearch Groovy language plugin

The Groovy language plugin allows to have groovy as the language of scripts to execute.

License

License

Categories

Categories

Groovy Languages Search Business Logic Libraries Elasticsearch
GroupId

GroupId

org.elasticsearch
ArtifactId

ArtifactId

elasticsearch-lang-groovy
Last Version

Last Version

2.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

Elasticsearch Groovy language plugin
The Groovy language plugin allows to have groovy as the language of scripts to execute.
Project URL

Project URL

https://github.com/elasticsearch/elasticsearch-lang-groovy/
Source Code Management

Source Code Management

http://github.com/elasticsearch/elasticsearch-lang-groovy

Download elasticsearch-lang-groovy

How to add to project

<!-- https://jarcasting.com/artifacts/org.elasticsearch/elasticsearch-lang-groovy/ -->
<dependency>
    <groupId>org.elasticsearch</groupId>
    <artifactId>elasticsearch-lang-groovy</artifactId>
    <version>2.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.elasticsearch/elasticsearch-lang-groovy/
implementation 'org.elasticsearch:elasticsearch-lang-groovy:2.2.0'
// https://jarcasting.com/artifacts/org.elasticsearch/elasticsearch-lang-groovy/
implementation ("org.elasticsearch:elasticsearch-lang-groovy:2.2.0")
'org.elasticsearch:elasticsearch-lang-groovy:jar:2.2.0'
<dependency org="org.elasticsearch" name="elasticsearch-lang-groovy" rev="2.2.0">
  <artifact name="elasticsearch-lang-groovy" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.elasticsearch', module='elasticsearch-lang-groovy', version='2.2.0')
)
libraryDependencies += "org.elasticsearch" % "elasticsearch-lang-groovy" % "2.2.0"
[org.elasticsearch/elasticsearch-lang-groovy "2.2.0"]

Dependencies

compile (2)

Group / Artifact Type Version
org.elasticsearch : elasticsearch jar 1.2.1
org.codehaus.groovy : groovy-all jar 2.2.1

runtime (1)

Group / Artifact Type Version
log4j : log4j jar 1.2.16

test (4)

Group / Artifact Type Version
org.apache.lucene : lucene-test-framework jar 4.8.1
org.elasticsearch : elasticsearch test-jar 1.2.1
org.hamcrest : hamcrest-core jar 1.3.RC2
org.hamcrest : hamcrest-library jar 1.3.RC2

Project Modules

There are no modules declared in this project.

Important: This plugin is not needed anymore from elasticsearch 1.4 and is not maintained.

Groovy lang Plugin for Elasticsearch

The Groovy language plugin allows to have groovy as the language of scripts to execute.

In order to install the plugin, simply run: bin/plugin -install elasticsearch/elasticsearch-lang-groovy/2.0.0.

Groovy Lang Plugin elasticsearch groovy Release date
3.0.0-SNAPSHOT master 2.2.1 XXXX-XX-XX

Please read documentation relative to the version you are using:

Using groovy with function_score

Let's say you want to use function_score API using groovy. Here is a way of doing it:

curl -XDELETE "http://localhost:9200/test"

curl -XPUT "http://localhost:9200/test/doc/1" -d '{
  "num": 1.0
}'

curl -XPUT "http://localhost:9200/test/doc/2?refresh" -d '{
  "num": 2.0
}'

curl -XGET "http://localhost:9200/test/_search" -d'
{
  "query": {
    "function_score": {
      "script_score": {
        "script": "Math.pow(doc[\"num\"].value, 2)",
        "lang": "groovy"
      }
    }
  }
}'

gives

{
   // ...
   "hits": {
      "total": 2,
      "max_score": 4,
      "hits": [
         {
            // ...
            "_score": 4
         },
         {
            // ...
            "_score": 1
         }
      ]
   }
}

Using groovy with script_fields

curl -XDELETE "http://localhost:9200/test"

curl -XPUT "http://localhost:9200/test/doc/1?refresh" -d'
{
  "obj1": {
   "test": "something"
  },
  "obj2": {
    "arr2": [ "arr_value1", "arr_value2" ]
  }
}'

curl -XGET "http://localhost:9200/test/_search" -d'
{
  "script_fields": {
    "s_obj1": {
      "script": "_source.obj1", "lang": "groovy"
    },
    "s_obj1_test": {
      "script": "_source.obj1.test", "lang": "groovy"
    },
    "s_obj2": {
      "script": "_source.obj2", "lang": "groovy"
    },
    "s_obj2_arr2": {
      "script": "_source.obj2.arr2", "lang": "groovy"
    }
  }
}'

gives

{
  // ...
  "hits": [
     {
        // ...
        "fields": {
           "s_obj2_arr2": [
              [
                 "arr_value1",
                 "arr_value2"
              ]
           ],
           "s_obj1_test": [
              "something"
           ],
           "s_obj2": [
              {
                 "arr2": [
                    "arr_value1",
                    "arr_value2"
                 ]
              }
           ],
           "s_obj1": [
              {
                 "test": "something"
              }
           ]
        }
     }
  ]
}

License

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

Copyright 2009-2014 Elasticsearch <http://www.elasticsearch.org>

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.
org.elasticsearch

elasticsearch

Versions

Version
2.2.0
2.0.0
2.0.0.RC1
1.5.0
1.4.0
1.3.0
1.2.0
1.1.0
1.0.0
0.18.7
0.18.6
0.18.5
0.18.4
0.18.3
0.18.2
0.18.1
0.18.0
0.17.10
0.17.9
0.17.8
0.17.7
0.17.6
0.17.5
0.17.4
0.17.3
0.17.2
0.17.1
0.17.0
0.16.5
0.16.4
0.16.3
0.16.2
0.16.1
0.16.0
0.15.2
0.15.1
0.15.0
0.14.4
0.14.3
0.14.2
0.14.1
0.14.0
0.13.1
0.13.0
0.12.1
0.12.0
0.11.0