# Using a pre-indexed shape filter with other properties

**URL:** <https://discuss.elastic.co/t/using-a-pre-indexed-shape-filter-with-other-properties/18314>\
**Category:** Elasticsearch\
**Created:** [June 25, 2014, 2:12am UTC](https://discuss.elastic.co/t/using-a-pre-indexed-shape-filter-with-other-properties/18314 "2014-06-25T02:12:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Nesbitt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/david_nesbitt/32/1460_2.png) [@David\_Nesbitt](https://discuss.elastic.co/u/David_Nesbitt)\
**Post date:** [June 25, 2014, 2:12am UTC](https://discuss.elastic.co/t/using-a-pre-indexed-shape-filter-with-other-properties/18314/1 "2014-06-25T02:12:00Z")

</div>

My goal is to validate that the geo points of indexed cities are contained  
within the multipolygon boundary of their corresponding country.

I have using the following as an initial guide:  
[http://people.mozilla.org/~wkahngreene/elastic/guide/reference/query-dsl/geo-shape-filter.html](http://people.mozilla.org/~wkahngreene/elastic/guide/reference/query-dsl/geo-shape-filter.html)

So the city index looks like:

$ curl -XPUT [http://localhost:9200/points](http://localhost:9200/points) -d '

{  
"mappings": {  
"city": {  
"properties": {  
"city": {"type": "string"},  
"country": {"type": "string"},  
"location": {"type": "geo\_shape"}  
}  
}  
}  
}  
'

$ curl -XPOST [http://localhost:9200/points/city/](http://localhost:9200/points/city/) -d '{"city": "Tokyo",  
"country": "Japan","location": {"type" : "point", "coordinates" :  
[139.6917, 35.6895]}}'

$ curl -XPUT [http://localhost:9200/shapes](http://localhost:9200/shapes) -d '  
{  
"mappings": {  
"country": {  
"properties": {  
"name": {"type": "string"},  
"shape": {"type": "geo\_shape"}  
}  
}  
}  
}  
'

$ curl -XPOST [http://localhost:9200/shapes/country/](http://localhost:9200/shapes/country/) -d  
'{"name":"Japan","shape":{"type":"multipolygon","coordinates":[[[[134.638428,34.149234],[134.766379,33.806335],[134.203416,33.201178],[133.79295,33.521985],[133.280268,33.28957],[133.014858,32.704567],[132.363115,32.989382],[132.371176,33.463642],[132.924373,34.060299],[133.492968,33.944621],[133.904106,34.364931],[134.638428,34.149234]]],[[[140.976388,37.142074],[140.59977,36.343983],[140.774074,35.842877],[140.253279,35.138114],[138.975528,34.6676],[137.217599,34.606286],[135.792983,33.464805],[135.120983,33.849071],[135.079435,34.596545],[133.340316,34.375938],[132.156771,33.904933],[130.986145,33.885761],[132.000036,33.149992],[131.33279,31.450355],[130.686318,31.029579],[130.20242,31.418238],[130.447676,32.319475],[129.814692,32.61031],[129.408463,33.296056],[130.353935,33.604151],[130.878451,34.232743],[131.884229,34.749714],[132.617673,35.433393],[134.608301,35.731618],[135.677538,35.527134],[136.723831,37.304984],[137.390612,36.827391],[138.857602,37.827485],[139.426405,38.215962],[140.05479,39.438807],[139.883379,40.563312],[140.305783,41.195005],[141.368973,41.37856],[141.914263,39.991616],[141.884601,39.180865],[140.959489,38.174001],[140.976388,37.142074]]],[[[143.910162,44.1741],[144.613427,43.960883],[145.320825,44.384733],[145.543137,43.262088],[144.059662,42.988358],[143.18385,41.995215],[141.611491,42.678791],[141.067286,41.584594],[139.955106,41.569556],[139.817544,42.563759],[140.312087,43.333273],[141.380549,43.388825],[141.671952,44.772125],[141.967645,45.551483],[143.14287,44.510358],[143.910162,44.1741]]]]}}'

I can explicitly query against a particular country as follows:

$ curl -XGET '[http://localhost:9200/points/city/\_search?pretty=true](http://localhost:9200/points/city/_search?pretty=true)' -d '

{  
"query": {  
"filtered" : {  
"query" : {  
"match\_all" : {}  
},  
"filter" : {  
"geo\_shape" : {  
"location" : {  
"indexed\_shape": {  
"id": "odsm2vWgT7ufBLjvmRMrNA",  
"type": "country",  
"index": "shapes",  
"shape\_field\_name": "shape"  
},  
"relation": "within"  
}  
}  
}  
}  
}  
}'

But is there a way that I can query that the city's country property  
matches the country's name property and the city's location is within the  
country's shape?

Thanks for any insights!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/806c4845-24c7-442b-b5fa-d66e0fca68d5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/806c4845-24c7-442b-b5fa-d66e0fca68d5%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 6, 2017, 1:20am UTC](https://discuss.elastic.co/t/using-a-pre-indexed-shape-filter-with-other-properties/18314/2 "2017-07-06T01:20:02Z")

</div>


