# Effective way to search for Addresses, City or States

**URL:** <https://discuss.elastic.co/t/effective-way-to-search-for-addresses-city-or-states/44088>\
**Category:** Elasticsearch\
**Created:** [March 10, 2016, 10:10pm UTC](https://discuss.elastic.co/t/effective-way-to-search-for-addresses-city-or-states/44088 "2016-03-10T22:10:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlossada](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@jlossada](https://discuss.elastic.co/u/jlossada)\
**Post date:** [March 10, 2016, 10:10pm UTC](https://discuss.elastic.co/t/effective-way-to-search-for-addresses-city-or-states/44088/1 "2016-03-10T22:10:10Z")

</div>

I am using Elasticsearch to search for events. Each has an Address, City, State, Zipcode. I was using a filed in the Mappings of the event called formatted\_address, that would be the whole address with city and state and zipcode combined in one field and I was just doing a match to that field. But I soon found out that searching for:

319 Rebel Ridge, Hemphill, Texas  
and searching for  
319 Rebel Ridge, Hemphill, TX

Had different results, depending on how a user would type the address when creating the event.

So I started using Google Places to auto suggest the address when creating the event and when searching for the event to make it more consistent, but I am still running into this problem of different ways one address can be typed.

Which is the best way to create a mapping for address and be able to deal with different forms of address. Specially dealing with States abbreviations.

I was reading through the documentation and saw that cross-fields Queries are best used for this scenario

Should I create a field for States abbreviations?

Thanks!

---

<div class="post-metadata">

**Author:** ![Shiv\_Naidu](https://avatars.discourse-cdn.com/v4/letter/s/e56c9b/32.png) [@Shiv\_Naidu](https://discuss.elastic.co/u/Shiv_Naidu)\
**Post date:** [March 10, 2016, 11:01pm UTC](https://discuss.elastic.co/t/effective-way-to-search-for-addresses-city-or-states/44088/2 "2016-03-10T23:01:14Z")

</div>

Hi Jaime,

Instead of normalizing the address, you put it in different fields and do a match. This helps to customize the query for a field. For example, since the Texas is a state that can be represented by TX, you can use a synonym file or table that tells Texas and TX or the same. Check out this document for how to use synonyms, [https://www.elastic.co/guide/en/elasticsearch/guide/current/using-synonyms.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/using-synonyms.html)

For example, if you have a document like this,

```
{
  "name": "josephiney_darakjy3@darakjy.org",
  "attributes": {
    "firstName": "Josephiney",
    "lastName": "Darakjy3",
    "companyName": "Chanay, Jeffrey A Esq",
    "address": "7 B Blue Ridge Blvd",
    "city": "Brighton",
    "state": "MI",
    "zip": 48116,
    "phone1": "810-292-9388",
    "phone2": "810-374-9840",
    "email": "josephiney_darakjy3@darakjy.org",
    "web": "http://www.chanayjeffreyaesq.com"
  }

```

}

You can run a query like this to do the search,

```
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "firstName": "Josephiney"
          }
        },
        {
          "match": {
            "lastName": "Darakjy3"
          }
        },
        {
          "bool": {
            "must": [
              {
                "match": {
                  "email": "josephiney_darakjy3@darakjy.org"
                }
              }
            ]
          }
        }
      ]
    }
  }
}
```

---

<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 5, 2017, 11:09pm UTC](https://discuss.elastic.co/t/effective-way-to-search-for-addresses-city-or-states/44088/3 "2017-07-05T23:09:18Z")

</div>


