Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search using BooleanQueryBuilder and GeoShapeQueryBuilder results in "Current context not an ARRAY but OBJECT" #3878

sowelie opened this Issue Oct 10, 2013 · 2 comments


None yet
2 participants
Copy link

sowelie commented Oct 10, 2013

First of all, thanks for building such an amazing service. I am loving my experience with ElasticSearch so far.

What I've run into is that trying to use the BooleanQueryBuilder in conjunction with the GeoShapeQueryBuilder is resulting in the following exception. Failed to build search source
    at org.elasticsearch.action.ActionRequestBuilder.execute(
    at org.elasticsearch.action.ActionRequestBuilder.execute(
    ... 38 more
Caused by: org.elasticsearch.common.jackson.core.JsonGenerationException: Current context not an ARRAY but OBJECT
    at org.elasticsearch.common.jackson.core.base.GeneratorBase._reportError(
    at org.elasticsearch.common.xcontent.json.JsonXContentGenerator.writeEndArray(
    at org.elasticsearch.common.xcontent.XContentBuilder.endArray(
    at org.elasticsearch.index.query.BoolQueryBuilder.doXArrayContent(
    at org.elasticsearch.index.query.BoolQueryBuilder.doXContent(
    at org.elasticsearch.index.query.BaseQueryBuilder.toXContent(
    ... 43 more

Here is my code to build and execute the query:

GeoShapeQueryBuilder geoQuery = QueryBuilders.geoShapeQuery("searchGeometry", new RectangleImpl(y1, y2, x1, x2, SpatialContext.GEO));
BoolQueryBuilder query = QueryBuilders.boolQuery();

if (featureIds.length > 0)
        query.must(QueryBuilders.termQuery("featureType", featureIds[0]));


SearchRequestBuilder request = esClient.prepareSearch("index_name")

SearchResponse response = request.execute().actionGet();

Am I doing something wrong? I have a feeling I am but it looks right to me.

This isn't a big deal for me, because I can just build a JSON query manually and that works perfectly fine. However it'd be nice to be able to use the QueryBuilders as make the code much easier to read.



This comment has been minimized.

Copy link

spinscale commented Oct 11, 2013


I can reproduce this and will take a further look at it... the combination of geoquery and term query leads to that (you get sort of a different exception when you switch term and geoquery in the must query).

Thanks for notifying!


This comment has been minimized.

Copy link

sowelie commented Oct 11, 2013


@spinscale spinscale closed this in e0b8b58 Oct 11, 2013

spinscale added a commit that referenced this issue Oct 11, 2013

Fix toXContent of GeoShapeQueryBuilder
A missing endObject() resulted in serialization errors.

Closes #3878

mute pushed a commit to mute/elasticsearch that referenced this issue Jul 29, 2015

Fix toXContent of GeoShapeQueryBuilder
A missing endObject() resulted in serialization errors.

Closes elastic#3878
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.