# Runtime error trying to run the ES sample code

**URL:** <https://discuss.elastic.co/t/runtime-error-trying-to-run-the-es-sample-code/4309>\
**Category:** Elasticsearch\
**Created:** [April 28, 2011, 12:09pm UTC](https://discuss.elastic.co/t/runtime-error-trying-to-run-the-es-sample-code/4309 "2011-04-28T12:09:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jondow](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jondow/32/2111_2.png) [@Jondow](https://discuss.elastic.co/u/Jondow)\
**Post date:** [April 28, 2011, 12:09pm UTC](https://discuss.elastic.co/t/runtime-error-trying-to-run-the-es-sample-code/4309/1 "2011-04-28T12:09:59Z")

</div>

Apologies if this is a silly error on my part, but I keep getting the  
following error when running the ES sample code:

Node started  
Caught: groovy.lang.MissingMethodException: No signature of method:  
org.elasticsearch.common.xcontent.XContentBuilder.map() is applicable  
for argument types: (java.lang.String) values: [this is a tweet]  
Possible solutions: map(java.util.Map), wait(), dump(), any(),  
wait(long), value(java.lang.String)  
at  
org.elasticsearch.groovy.common.xcontent.GXContentBuilder.buildAsBytes(GXContentBuilder.groovy:  
64)  
at org.elasticsearch.groovy.client.GClient  
$\_\_clinit\_\_closure3.doCall(GClient.groovy:65)  
at EsTwitterTest$\_run\_closure1.doCall(EsTwitterTest.groovy:25)  
at EsTwitterTest$\_run\_closure1.doCall(EsTwitterTest.groovy)  
at org.elasticsearch.groovy.client.GClient.index(GClient.groovy:182)  
at EsTwitterTest.run(EsTwitterTest.groovy:21)

The code I'm trying to run is as follows:

def startNode() {  
def nodeBuilder = new org.elasticsearch.groovy.node.GNodeBuilder()  
nodeBuilder.settings {  
node {  
local = true  
}  
gateway {  
type = "none"  
}  
}  
nodeBuilder.node()  
}

def node = startNode()  
println "settings $node.settings.asMap"  
println "Node started"  
future = node.client.index {  
index "twitter"  
type "tweet"  
id "1"  
source {  
user = "kimchy"  
message = "this is a tweet"  
}  
}  
println "Indexed $future.response.index/$future.response.type/  
$future.response.id"  
node.close()

I've played with various permutations of this code, and find that the  
only thing that fixes it is if I add a:  
complex {  
foo = "bar"  
}  
in the source { } block. Also creating the node in the various ways  
doesn't make any difference. I got this error running it from my IDE  
(Intellij IDEA) and from the command line.

Thanks,  
Darryl

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [April 28, 2011, 9:48pm UTC](https://discuss.elastic.co/t/runtime-error-trying-to-run-the-es-sample-code/4309/2 "2011-04-28T21:48:10Z")

</div>

Are you running it as a script or as a groovy class/code (donnno the correct term for it). If as a script, then you might want to set GXContentBuilder.rootResolveStrategy to a different value than Closure.OWNER\_FIRST.

Basically, I think the problem you get is in converting Groovy Closures into json (using elasticsearch XContent framework). I basically copied the Grails json builder as is into GXContentBuilder, so it should behave the same. Not a groovy expert...

-shay.banon  
On Thursday, April 28, 2011 at 3:09 PM, Jondow wrote:  
Apologies if this is a silly error on my part, but I keep getting the

> following error when running the ES sample code:
> 
> Node started  
> Caught: groovy.lang.MissingMethodException: No signature of method:  
> org.elasticsearch.common.xcontent.XContentBuilder.map() is applicable  
> for argument types: (java.lang.String) values: [this is a tweet]  
> Possible solutions: map(java.util.Map), wait(), dump(), any(),  
> wait(long), value(java.lang.String)  
> at  
> org.elasticsearch.groovy.common.xcontent.GXContentBuilder.buildAsBytes(GXContentBuilder.groovy:  
> 64)  
> at org.elasticsearch.groovy.client.GClient  
> $\_\_clinit\_\_closure3.doCall(GClient.groovy:65)  
> at EsTwitterTest$\_run\_closure1.doCall(EsTwitterTest.groovy:25)  
> at EsTwitterTest$\_run\_closure1.doCall(EsTwitterTest.groovy)  
> at org.elasticsearch.groovy.client.GClient.index(GClient.groovy:182)  
> at EsTwitterTest.run(EsTwitterTest.groovy:21)
> 
> The code I'm trying to run is as follows:
> 
> def startNode() {  
> def nodeBuilder = new org.elasticsearch.groovy.node.GNodeBuilder()  
> nodeBuilder.settings {  
> node {  
> local = true  
> }  
> gateway {  
> type = "none"  
> }  
> }  
> nodeBuilder.node()  
> }
> 
> def node = startNode()  
> println "settings $node.settings.asMap"  
> println "Node started"  
> future = node.client.index {  
> index "twitter"  
> type "tweet"  
> id "1"  
> source {  
> user = "kimchy"  
> message = "this is a tweet"  
> }  
> }  
> println "Indexed $future.response.index/$future.response.type/  
> $future.response.id"  
> node.close()
> 
> I've played with various permutations of this code, and find that the  
> only thing that fixes it is if I add a:  
> complex {  
> foo = "bar"  
> }  
> in the source { } block. Also creating the node in the various ways  
> doesn't make any difference. I got this error running it from my IDE  
> (Intellij IDEA) and from the command line.
> 
> Thanks,  
> Darryl

---

<div class="post-metadata">

**Author:** ![Jondow](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jondow/32/2111_2.png) [@Jondow](https://discuss.elastic.co/u/Jondow)\
**Post date:** [April 29, 2011, 8:06am UTC](https://discuss.elastic.co/t/runtime-error-trying-to-run-the-es-sample-code/4309/3 "2011-04-29T08:06:24Z")

</div>

That was it. I set:

GXContentBuilder.rootResolveStrategy = Closure.DELEGATE\_FIRST;

and now it works as it says on the tin. Thanks Shay!

- Darryl

On Apr 28, 11:48 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> Are you running it as a script or as a groovy class/code (donnno the correct term for it). If as a script, then you might want to set GXContentBuilder.rootResolveStrategy to a different value than Closure.OWNER\_FIRST.
> 
> Basically, I think the problem you get is in converting Groovy Closures into json (using elasticsearch XContent framework). I basically copied the Grails json builder as is into GXContentBuilder, so it should behave the same. Not a groovy expert...
> 
> -shay.banonOn Thursday, April 28, 2011 at 3:09 PM, Jondow wrote:
> 
> Apologies if this is a silly error on my part, but I keep getting the
> 
> > following error when running the ES sample code:
> 
> > Node started  
> > Caught: groovy.lang.MissingMethodException: No signature of method:  
> > org.elasticsearch.common.xcontent.XContentBuilder.map() is applicable  
> > for argument types: (java.lang.String) values: [this is a tweet]  
> > Possible solutions: map(java.util.Map), wait(), dump(), any(),  
> > wait(long), value(java.lang.String)  
> > at  
> > org.elasticsearch.groovy.common.xcontent.GXContentBuilder.buildAsBytes(GXContentBuilder.groovy:  
> > 64)  
> > at org.elasticsearch.groovy.client.GClient  
> > $\_\_clinit\_\_closure3.doCall(GClient.groovy:65)  
> > at EsTwitterTest$\_run\_closure1.doCall(EsTwitterTest.groovy:25)  
> > at EsTwitterTest$\_run\_closure1.doCall(EsTwitterTest.groovy)  
> > at org.elasticsearch.groovy.client.GClient.index(GClient.groovy:182)  
> > at EsTwitterTest.run(EsTwitterTest.groovy:21)
> 
> > The code I'm trying to run is as follows:
> 
> > def startNode() {  
> > def nodeBuilder = new org.elasticsearch.groovy.node.GNodeBuilder()  
> > nodeBuilder.settings {  
> > node {  
> > local = true  
> > }  
> > gateway {  
> > type = "none"  
> > }  
> > }  
> > nodeBuilder.node()  
> > }
> 
> > def node = startNode()  
> > println "settings $node.settings.asMap"  
> > println "Node started"  
> > future = node.client.index {  
> > index "twitter"  
> > type "tweet"  
> > id "1"  
> > source {  
> > user = "kimchy"  
> > message = "this is a tweet"  
> > }  
> > }  
> > println "Indexed $future.response.index/$future.response.type/  
> > $future.response.id"  
> > node.close()
> 
> > I've played with various permutations of this code, and find that the  
> > only thing that fixes it is if I add a:  
> > complex {  
> > foo = "bar"  
> > }  
> > in the source { } block. Also creating the node in the various ways  
> > doesn't make any difference. I got this error running it from my IDE  
> > (Intellij IDEA) and from the command line.
> 
> > Thanks,  
> > Darryl

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 4:07am UTC](https://discuss.elastic.co/t/runtime-error-trying-to-run-the-es-sample-code/4309/4 "2017-07-06T04:07:25Z")

</div>


