Effective way to search for Addresses, City or States

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!

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

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