Error using multiple geospan queries as bool should clauses

Hi,

I'm trying to return documents that contain a geoshape point which is in any of a given set of pre-indexed areas. To do this, I'm adding 2 geo span queries as should clauses to a bool query. However, I'm receiving a 500 error as the response. Please see the example below:

curl -XPOST http://localhost:9200/docs/doc/_search -H 'Content-Type: application/json' -d '
{
"query": {
	"bool": {
		"should": [{
			"geo_shape": {
				"location.point": {
					"indexed_shape": {
						"index": "areas",
						"type": "area",
						"id": "14",
						"path": "location"
					}
				}
			}
		}, {
			"geo_shape": {
				"location.point": {
					"indexed_shape": {
						"index": "areas",
						"type": "area",
						"id": "15",
						"path": "location"
					}
				}
			}
		}]
	}
}
}

This returns the following error:

{"error":{"root_cause":[{"type":"array_index_out_of_bounds_exception","reason":"1"}],"type":"array_index_out_of_bounds_exception","reason":"1"},"status":500}

Removing either of the should clauses and re-running the query returns results as expected. My first question is if anyone can see anything obviously wrong with the query?

Failing that, is this a known behaviour or does anyone know a better way I can approach this task?

Thanks!

Some further info that might help clarify the question. Here are the relevant segments of the mappings for the 2 indices:

{
"docs": {
    "mappings": {
        "doc": {
            "properties": {
                "location": {
                    "properties": {
                        "point": {
                            "type": "geo_shape",
                            "points_only": true
                        }
                    }
                }
            }
        }
    }
}
}


{
"areas": {
    "mappings": {
        "area": {
            "properties": {
                "location": {
                    "type": "geo_shape"
                }
            }
        }
    }
}
}

Some further info I should have added! Here is the stack trace that is getting thrown in the ES logs:

[2018-01-04T11:39:43,852][WARN ][r.suppressed             ] path: /docs/doc/_search, params: {index=docs, type=doc}
java.lang.ArrayIndexOutOfBoundsException: 1
at org.elasticsearch.index.query.GeoShapeQueryBuilder$1.onResponse(GeoShapeQueryBuilder.java:410) [elasticsearch-6.0.0.jar:6.0.0]
at org.elasticsearch.index.query.GeoShapeQueryBuilder$1.onResponse(GeoShapeQueryBuilder.java:388) [elasticsearch-6.0.0.jar:6.0.0]
at org.elasticsearch.action.support.TransportAction$1.onResponse(TransportAction.java:85) [elasticsearch-6.0.0.jar:6.0.0]
at org.elasticsearch.action.support.TransportAction$1.onResponse(TransportAction.java:81) [elasticsearch-6.0.0.jar:6.0.0]
at org.elasticsearch.action.support.single.shard.TransportSingleShardAction$AsyncSingleAction$2.handleResponse(TransportSingleShardAction.java:247) [elasticsearch-6.0.0.jar:6.0.0]
at org.elasticsearch.action.support.single.shard.TransportSingleShardAction$AsyncSingleAction$2.handleResponse(TransportSingleShardAction.java:233) [elasticsearch-6.0.0.jar:6.0.0]
at org.elasticsearch.transport.TransportService$ContextRestoreResponseHandler.handleResponse(TransportService.java:1062) [elasticsearch-6.0.0.jar:6.0.0]
at org.elasticsearch.transport.TransportService$DirectResponseChannel.processResponse(TransportService.java:1136) [elasticsearch-6.0.0.jar:6.0.0]
at org.elasticsearch.transport.TransportService$DirectResponseChannel.sendResponse(TransportService.java:1126) [elasticsearch-6.0.0.jar:6.0.0]
at org.elasticsearch.transport.TransportService$DirectResponseChannel.sendResponse(TransportService.java:1115) [elasticsearch-6.0.0.jar:6.0.0]
at org.elasticsearch.transport.DelegatingTransportChannel.sendResponse(DelegatingTransportChannel.java:60) [elasticsearch-6.0.0.jar:6.0.0]
at org.elasticsearch.transport.RequestHandlerRegistry$TransportChannelWrapper.sendResponse(RequestHandlerRegistry.java:108) [elasticsearch-6.0.0.jar:6.0.0]
at org.elasticsearch.action.support.single.shard.TransportSingleShardAction$ShardTransportHandler.messageReceived(TransportSingleShardAction.java:295) [elasticsearch-6.0.0.jar:6.0.0]
at org.elasticsearch.action.support.single.shard.TransportSingleShardAction$ShardTransportHandler.messageReceived(TransportSingleShardAction.java:287) [elasticsearch-6.0.0.jar:6.0.0]
at org.elasticsearch.transport.TransportRequestHandler.messageReceived(TransportRequestHandler.java:30) [elasticsearch-6.0.0.jar:6.0.0]
at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:66) [elasticsearch-6.0.0.jar:6.0.0]
at org.elasticsearch.transport.TransportService$7.doRun(TransportService.java:659) [elasticsearch-6.0.0.jar:6.0.0]
at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:638) [elasticsearch-6.0.0.jar:6.0.0]
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-6.0.0.jar:6.0.0]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_131]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_131]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_131]

For anybody who stumbles upon this thread:

I implemented a workaround of creating a single MultiPolygon that combined all the MultiPolygons i was interested in so that I only had one geo_shape query within my bool query.

This works but means I can unfortunately no longer used stored shapes as I'm building the shape at query time.

We are running into the same issue with ES 6.0. We use indexed shapes to perform geospatial queries and cannot combine them into a single multipolygon without a significant rewrite. Could someone from the ES team comment?
Thanks,
Trang

This seems to be a serious bug wrt indexed shape support: applications that used to work on ES 5.5 now breaks with ES 6.0.

I am seeing the same issue with my codebase, and have opened an issue on GitHub here: https://github.com/elastic/elasticsearch/issues/28699

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.