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

Closed
sowelie opened this Issue Oct 10, 2013 · 2 comments

Comments

Projects
None yet
2 participants
@sowelie
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.

org.elasticsearch.search.builder.SearchSourceBuilderException: Failed to build search source
    at org.elasticsearch.search.builder.SearchSourceBuilder.buildAsBytes(SearchSourceBuilder.java:579)
    at org.elasticsearch.action.search.SearchRequest.source(SearchRequest.java:258)
    at org.elasticsearch.action.search.SearchRequestBuilder.doExecute(SearchRequestBuilder.java:839)
    at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:85)
    at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:59)
    at com.tomtom.lbs.vectordb.data.services.ElasticSearchService.search(ElasticSearchService.java:119)
    ... 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(GeneratorBase.java:444)
    at org.elasticsearch.common.jackson.dataformat.smile.SmileGenerator.writeEndArray(SmileGenerator.java:553)
    at org.elasticsearch.common.xcontent.json.JsonXContentGenerator.writeEndArray(JsonXContentGenerator.java:59)
    at org.elasticsearch.common.xcontent.XContentBuilder.endArray(XContentBuilder.java:227)
    at org.elasticsearch.index.query.BoolQueryBuilder.doXArrayContent(BoolQueryBuilder.java:182)
    at org.elasticsearch.index.query.BoolQueryBuilder.doXContent(BoolQueryBuilder.java:149)
    at org.elasticsearch.index.query.BaseQueryBuilder.toXContent(BaseQueryBuilder.java:65)
    at org.elasticsearch.search.builder.SearchSourceBuilder.toXContent(SearchSourceBuilder.java:601)
    at org.elasticsearch.search.builder.SearchSourceBuilder.buildAsBytes(SearchSourceBuilder.java:576)
    ... 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]));

query.must(geoQuery);

SearchRequestBuilder request = esClient.prepareSearch("index_name")
        .setSearchType(SearchType.QUERY_THEN_FETCH)
        .setQuery(query)
        .setFrom(0)
        .setSize(maxResults)
        .setExplain(false);

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.

Thanks!

@spinscale

This comment has been minimized.

Copy link
Member

spinscale commented Oct 11, 2013

Hey,

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!

@sowelie

This comment has been minimized.

Copy link
Author

sowelie commented Oct 11, 2013

Thanks!

@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.