I'm Having a really hard time trying to get an address based index to return results in the same was as an autocomplete works, I have been trying two different methods, I started out trying to use nGram's and custom analyzers but i have really struggled to get relevant results to show how one would expect when using an address autocomplete.
The second method i have focused on is to see if the completion suggester elasticsearch ships with would be any easier to get working but i seem to be hitting a road block in every direction.
We send regular client-side API calls based on the input value on every key-up.
the issue i seem to face is either.. I'm not returning relevant enough results and if / when they are relevant an additional character partial word can force no results to be returned at all.
An example would be for the following address: 7 West Hill Gardens, West Hill EX9 6BL
My documents are stored like so:
Completion Suggester
"id": "1",
"address": "7, Westhill Gardens, Bromyard HR74HW",
"suggest": "7, Westhill Gardens, Bromyard HR74HW"
Completions Suggester Mappings:
{
"mappings": {
"addresses": {
"properties": {
"suggest": {
"type": "completion",
"preserve_separators": false,
"analyzer": "standard",
"search_analyzer": "standard"
},
"address": {
"type": "text"
},
"id": {
"type": "keyword"
}
}
}
}
}
Note i set the preserve_separators
to false
in the suggester to allow for west hill to also be matched as westhill, This works fine on the suggester however in my nGram index im unsure how i enable to same functionality with mappings and i believe that may be part of the issue i have with not returning relevant results.
With the suggester is when i query for 7 westhill gardens
using the following query:
{
"suggest": {
"suggestions": {
"prefix": "7 westhill gardens",
"completion": {
"field": "suggest",
"fuzzy": {
"fuzziness": 2 // Also tried with no fuzzy and fuzziness: 1
}
}
}
}
}
The following results are returned:
"address": "7, Westhill Gardens, Brackley NN136AA",
"address": "7, Westhill Gardens, Bromyard HR74HW",
"address": "7, West Hill Gardens, West Hill, Budleigh Salterton EX96BL",
However if i remove the number 7 from the query and perform this query it returns no results, This is kind of a key issue as not all users will start their query with the given house number and it is quite common to perform the search as west hill gardens
as appose to 7 west hill gardens
{
"suggest": {
"suggestions": {
"prefix": "westhill gardens",
"completion": {
"field": "suggest",
"fuzzy": {
"fuzziness": 2
}
}
}
}
}
And lastly if i query for just the house number as shown below, No results are returned.
{
"suggest": {
"suggestions": {
"prefix": "7 EX9 6BL",
"completion": {
"field": "suggest",
"fuzzy": {
"fuzziness": 2
}
}
}
}
}
I'm hoping someone with more experience than me can shed some thoughts on what the best approach would be and if i should stick to nGrams and try and get a custom analyzer / filter approach working.. Or am i just doing it totally wrong?! I have only just started to learn elasticsearch so i send my apologies if my terminology is incorrect.