Groovy & Multiple term filters problem


(Mark Johnson) #1

Im using Groovy. With the following query below im getting the error (bold). can anyone tell me where I am going wrong with my query,
cheers

Class
java.lang.NullPointerException
Message
Cannot invoke method getAt() on null object

query {
filtered {
query {
query_string (query: query_terms)
}
filter {
and {
filters [{
term {
subject = params.subject
}
}
{
term {
provid = params.provider
}
}]
_name = "is_this_needed"
}
}

}
}
}
facets {
subject {
terms {
field = 'subject'
}
}
provider {
terms {
field = 'provid'
}
}
}


(Shay Banon) #2

Maybe its the part that transforms the closure to a json? Where is the
failure coming from? If so, I just took that code from grails, it seems to
have its quirks, not sure why since I am not a groovy expert...

On Fri, Jan 20, 2012 at 4:02 PM, Mark Johnson Mark@k-int.com wrote:

Im using Groovy. With the following query below im getting the error
(bold). can anyone tell me where I am going wrong with my query,
cheers

Class
java.lang.NullPointerException
Message
Cannot invoke method getAt() on null object

query {
filtered {
query {
query_string (query: query_terms)
}
filter {
and {
filters [{
term {
subject =
params.subject
}
}
{
term {
provid =
params.provider
}
}]
_name = "is_this_needed"
}
}
}
}
}
facets {
subject {
terms {
field = 'subject'
}
}
provider {
terms {
field = 'provid'
}
}
}

--
View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/Groovy-Multiple-term-filters-problem-tp3675518p3675518.html
Sent from the ElasticSearch Users mailing list archive at Nabble.com.


(Mark Johnson) #3

The problem comes at the line:

filters [{

It doesnt seem to like the array use

would it be useful for me to print the Trace here?


(egaumer) #4

Keep in mind that what you're writing is groovy, not actual JSON.
JSONBuilder (grails) is there to provide a DSL. I typically just write pure
groovy code because of all the JSONBuilder quirks. It also makes modifying
query objects easier.

Try converting your filter object to a groovy map. This is essentially what
JSONBuilder would produce anyway (a map from a closure).

filters [
[term:[subject:params.subject]],
[term:[provid:params.provider]]
]

You can rewrite the entire query as a map.


(Mark Johnson) #5

Thanks Eric I'll give this a go on Monday


(ianibbo) #6

Heya all.. I've been looking at this for mark over the weekend... The stack-trace is attached below. It seems to cleanly describe the method calls assigned via the metaClass. Reading the code for GCContextBuilder there are some references to an element() call that I can't quite put into context... If anyone can point me in the right direction I'm more than happy to dig deeper...

Eric, you suggest compiling a pure json object, but I can't see a way to pass a pure groovy map through GClient... Are you suggesting doing away with GClient altogether and then just using a http client to post a manually constructed json object at the server?

Cheers all, any ideas most welcome!

Ian.

Cannot invoke method getAt() on null object. Stacktrace follows:
java.lang.NullPointerException: Cannot invoke method getAt() on null object
at com.k_int.xcri.SearchController$_index_closure1_closure3_closure4_closure6_closure8_closure9$$ENMgvvLk.doCall(SearchController.groovy:54)
at org.elasticsearch.groovy.common.xcontent.GXContentBuilder.handleClosureNode(GXContentBuilder.groovy:156)
at org.elasticsearch.groovy.common.xcontent.GXContentBuilder.invokeMethod(GXContentBuilder.groovy:118)
at com.k_int.xcri.SearchController$_index_closure1_closure3_closure4_closure6_closure8$$ENMgvvLk.doCall(SearchController.groovy:52)
at org.elasticsearch.groovy.common.xcontent.GXContentBuilder.handleClosureNode(GXContentBuilder.groovy:156)
at org.elasticsearch.groovy.common.xcontent.GXContentBuilder.invokeMethod(GXContentBuilder.groovy:118)
at com.k_int.xcri.SearchController$_index_closure1_closure3_closure4_closure6$$ENMgvvLk.doCall(SearchController.groovy:51)
at org.elasticsearch.groovy.common.xcontent.GXContentBuilder.handleClosureNode(GXContentBuilder.groovy:156)
at org.elasticsearch.groovy.common.xcontent.GXContentBuilder.invokeMethod(GXContentBuilder.groovy:118)
at com.k_int.xcri.SearchController$_index_closure1_closure3_closure4$$ENMgvvLk.doCall(SearchController.groovy:47)
at org.elasticsearch.groovy.common.xcontent.GXContentBuilder.handleClosureNode(GXContentBuilder.groovy:156)
at org.elasticsearch.groovy.common.xcontent.GXContentBuilder.invokeMethod(GXContentBuilder.groovy:118)
at com.k_int.xcri.SearchController$_index_closure1_closure3$$ENMgvvLk.doCall(SearchController.groovy:45)
at org.elasticsearch.groovy.common.xcontent.GXContentBuilder.buildRoot(GXContentBuilder.groovy:73)
at org.elasticsearch.groovy.common.xcontent.GXContentBuilder.build(GXContentBuilder.groovy:47)
at org.elasticsearch.groovy.common.xcontent.GXContentBuilder.buildAsBytes(GXContentBuilder.groovy:63)
at org.elasticsearch.groovy.client.GClient$__clinit__closure15.doCall(GClient.groovy:107)
at com.k_int.xcri.SearchController$_index_closure1$$ENMgvvLk.doCall(SearchController.groovy:42)
at org.elasticsearch.groovy.client.GClient.search(GClient.groovy:308)
at com.k_int.xcri.SearchController$$ENMgvvLk.index(SearchController.groovy:82)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)


(system) #7