# Translating zipcode to long/lat in query?

**URL:** <https://discuss.elastic.co/t/translating-zipcode-to-long-lat-in-query/75697>\
**Category:** Elasticsearch\
**Created:** [February 20, 2017, 9:33am UTC](https://discuss.elastic.co/t/translating-zipcode-to-long-lat-in-query/75697 "2017-02-20T09:33:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zach\_Moshe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zach_moshe/32/15689_2.png) [@Zach\_Moshe](https://discuss.elastic.co/u/Zach_Moshe)\
**Post date:** [February 20, 2017, 9:33am UTC](https://discuss.elastic.co/t/translating-zipcode-to-long-lat-in-query/75697/1 "2017-02-20T09:33:57Z")

</div>

HI,  
I have an index with documents that contain a geo\_point field.  
I want to have a query where the user gives a zipcode, I translate it to long/lat based on some static mapping and return relevant results with the geo\_distance query. I don't want the client side to do the translation and submit long/lats.

Can it be done? I looked at ingest node scripting to alter the query, but couldn't find a processor that can do a key-value lookup on another index (that will hold all mappings) or read mapping from a file on disk.  
Can a painless (or other language) script query an ES index?

Any other ideas?

Thanks!  
Zach

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [February 20, 2017, 10:03am UTC](https://discuss.elastic.co/t/translating-zipcode-to-long-lat-in-query/75697/2 "2017-02-20T10:03:18Z")

</div>

> [@Zach\_Moshe](#):
>
> I looked at ingest node scripting to alter the query

Ingest node is for preparing documents to index, not queries to run.

You'd need to get hold of the data that has coordinates for each zipcode and you could put that into elasticsearch and then run a preliminary query to get the coordinates for a given postcode. Instead you could use some custom server-side logic to cache all the zipcodes in memory and look coordinates up using that.

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [February 20, 2017, 10:14am UTC](https://discuss.elastic.co/t/translating-zipcode-to-long-lat-in-query/75697/3 "2017-02-20T10:14:46Z")

</div>

Yes, it can be done.

It is a special case of my reference plugin [https://github.com/jprante/elasticsearch-analysis-reference](https://github.com/jprante/elasticsearch-analysis-reference) where a new field type could be introduced to translate a zip code to a geo field. The translation could be implemented by a lookup of geo coordinates stored in a zip code index.

---

<div class="post-metadata">

**Author:** ![Zach\_Moshe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zach_moshe/32/15689_2.png) [@Zach\_Moshe](https://discuss.elastic.co/u/Zach_Moshe)\
**Post date:** [February 20, 2017, 10:28am UTC](https://discuss.elastic.co/t/translating-zipcode-to-long-lat-in-query/75697/4 "2017-02-20T10:28:56Z")

</div>

thanks! I'll have a look.  
Does the plugin also work with ES 5.x? (GIthub only mentioned 2.x)

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [February 20, 2017, 11:48am UTC](https://discuss.elastic.co/t/translating-zipcode-to-long-lat-in-query/75697/5 "2017-02-20T11:48:14Z")

</div>

Note, the reference plugin is not ready for your use case "referencing lat/lon from given zip code". You'd have to implement such a plugin.

ES 5.x is work in progress.

If you want to see a preview release, I have a plugin bundle ready for ES 5.1.1 of all my analysis plugins, where the reference plugin is already part of. See [https://github.com/jprante/elasticsearch-plugin-bundle](https://github.com/jprante/elasticsearch-plugin-bundle)

---

<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 20, 2017, 11:48am UTC](https://discuss.elastic.co/t/translating-zipcode-to-long-lat-in-query/75697/6 "2017-03-20T11:48:21Z")

</div>

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