I have the following mapping in AWS Elasticsearch index
"Location": {
"type": "geo_shape",
"tree": "quadtree"
}
The following geo_shape query works perfectly fine on my Kibana console
GET test/doc/_search
{
"query": {
"geo_shape": {
"Location": {
"shape": {
"type": "point",
"coordinates": [-122.28,37.83]
},
"relation": "intersects"
}
}
}
}
I am trying to perform the similar query using Elasticsearch Java High Level Rest Client 6.6.1
//Create new CountRequest for index test
CountRequest countRequest = new CountRequest("test");
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
QueryBuilder qb = QueryBuilders.matchAllQuery();
Coordinate coordinate = new Coordinate(-122.28, 37.83);
List<Coordinate> coordinateList = new ArrayList<>();
coordinateList.add(coordinate);
// ElasticShapeBuilder is my class which extends the the abstract class org.elasticsearch.common.geo.builders.ShapeBuilder
ShapeBuilder shapeBuilder = new ElasticShapeBuilder(coordinateList);
QueryBuilder qb2 = QueryBuilders.geoShapeQuery("Location", shapeBuilder);
QueryBuilder qb3 = QueryBuilders.boolQuery().must(qb).filter(qb2);
searchSourceBuilder.query(qb3);
countRequest.source(searchSourceBuilder);
CountResponse countResponse = highRestClient.count(countRequest, RequestOptions.DEFAULT);
I get the following error
com.fasterxml.jackson.core.JsonGenerationException: Can not write a field name, expecting a value
Suppressed: java.lang.IllegalStateException: Failed to close the XContentBuilder
Caused by: java.io.IOException: Unclosed object or array found