/
DoSomethingWithES.groovy
47 lines (36 loc) · 999 Bytes
/
DoSomethingWithES.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import org.elasticsearch.groovy.node.GNode
import org.elasticsearch.groovy.node.GNodeBuilder
import org.elasticsearch.search.SearchHit
import static org.elasticsearch.groovy.node.GNodeBuilder.nodeBuilder
org.elasticsearch.groovy.common.xcontent.GXContentBuilder.rootResolveStrategy = Closure.DELEGATE_FIRST;
// Start the connection
GNodeBuilder nodeBuilder = nodeBuilder();
nodeBuilder.settings {
node {
client = true
}
cluster {
name = "jc-elasticsearch"
}
}
GNode node = nodeBuilder.node()
// Do something with the connection
def search = node.client.search {
indices "ro"
types "rijksoverheid"
source {
query {
term(title_nl: "drinken")
}
}
}
search.response.hits.each {SearchHit hit ->
println "Got hit $hit.id from $hit.index/$hit.type"
println "Title: $hit.source.title_nl"
}
//System.in.withReader {
// print 'input: '
// println it.readLine()
//}
// close the connection
node.stop().close()