# Error using multiple geospan queries as bool should clauses

**URL:** <https://discuss.elastic.co/t/error-using-multiple-geospan-queries-as-bool-should-clauses/113945>\
**Category:** Elasticsearch\
**Created:** [January 3, 2018, 3:07pm UTC](https://discuss.elastic.co/t/error-using-multiple-geospan-queries-as-bool-should-clauses/113945 "2018-01-03T15:07:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mecco](https://avatars.discourse-cdn.com/v4/letter/m/a9adbd/32.png) [@mecco](https://discuss.elastic.co/u/mecco)\
**Post date:** [January 3, 2018, 3:07pm UTC](https://discuss.elastic.co/t/error-using-multiple-geospan-queries-as-bool-should-clauses/113945/1 "2018-01-03T15:07:32Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![mecco](https://avatars.discourse-cdn.com/v4/letter/m/a9adbd/32.png) [@mecco](https://discuss.elastic.co/u/mecco)\
**Post date:** [January 3, 2018, 3:27pm UTC](https://discuss.elastic.co/t/error-using-multiple-geospan-queries-as-bool-should-clauses/113945/2 "2018-01-03T15:27:22Z")

</div>

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"
                }
            }
        }
    }
}
}
```

---

<div class="post-metadata">

**Author:** ![mecco](https://avatars.discourse-cdn.com/v4/letter/m/a9adbd/32.png) [@mecco](https://discuss.elastic.co/u/mecco)\
**Post date:** [January 4, 2018, 11:43am UTC](https://discuss.elastic.co/t/error-using-multiple-geospan-queries-as-bool-should-clauses/113945/3 "2018-01-04T11:43:07Z")

</div>

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]
```

---

<div class="post-metadata">

**Author:** ![mecco](https://avatars.discourse-cdn.com/v4/letter/m/a9adbd/32.png) [@mecco](https://discuss.elastic.co/u/mecco)\
**Post date:** [January 25, 2018, 9:11am UTC](https://discuss.elastic.co/t/error-using-multiple-geospan-queries-as-bool-should-clauses/113945/4 "2018-01-25T09:11:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![trangvenn](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@trangvenn](https://discuss.elastic.co/u/trangvenn)\
**Post date:** [January 29, 2018, 3:58pm UTC](https://discuss.elastic.co/t/error-using-multiple-geospan-queries-as-bool-should-clauses/113945/5 "2018-01-29T15:58:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![trangvenn](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@trangvenn](https://discuss.elastic.co/u/trangvenn)\
**Post date:** [January 31, 2018, 1:50pm UTC](https://discuss.elastic.co/t/error-using-multiple-geospan-queries-as-bool-should-clauses/113945/6 "2018-01-31T13:50:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ncavig](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ncavig/32/14479_2.png) [@ncavig](https://discuss.elastic.co/u/ncavig)\
**Post date:** [February 15, 2018, 11:17pm UTC](https://discuss.elastic.co/t/error-using-multiple-geospan-queries-as-bool-should-clauses/113945/7 "2018-02-15T23:17:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 15, 2018, 11:17pm UTC](https://discuss.elastic.co/t/error-using-multiple-geospan-queries-as-bool-should-clauses/113945/8 "2018-03-15T23:17:29Z")

</div>

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