Mapping seach cities by name

55 Views Asked by At

I'm building an autocomplete input to search in a city database.

When I type "Wash", I'd like to propose Washington. Now when I type "Wash" I have nothing, With "washingt" ES found "washington".

I'm using FOS elastica.

mapping:

  indexes:
cities:
  finder: ~
  use_alias: false
  settings:
    analysis:
      analyzer:
        text_analyzer:
          tokenizer: 'whitespace'
          filter: [ lowercase, trim, asciifolding, elision, name_filter ]
      filter:
        name_filter:
          type: edgeNGram
          max_gram: 100
          min_gram: 2
  properties:
    zipCode:
      type: keyword
    name:
      analyzer: text_analyzer

ES requets:

{
"query": {
    "query_string": {
        "query": "washingt",
        "fields": [
            "name",
            "zipCode"
        ]
    }
},
"from": 0,
"size": 1000
}

Any ideas what I'm missing?

Edit:

POST cities/_analyze { "field": "name", "text": ["washington"] }

"tokens": [
{
"token": "w",
"start_offset": 0,
"end_offset": 10,
"type": "<ALPHANUM>",
"position": 0
}
,
{
"token": "wa",
"start_offset": 0,
"end_offset": 10,
"type": "<ALPHANUM>",
"position": 0
}
,
{
"token": "was",
"start_offset": 0,
"end_offset": 10,
"type": "<ALPHANUM>",
"position": 0
}
,
{
"token": "wash",
"start_offset": 0,
"end_offset": 10,
"type": "<ALPHANUM>",
"position": 0
}
,
{
"token": "washi",
"start_offset": 0,
"end_offset": 10,
"type": "<ALPHANUM>",
"position": 0
}
,
{
"token": "washin",
"start_offset": 0,
"end_offset": 10,
"type": "<ALPHANUM>",
"position": 0
}
,
{
"token": "washing",
"start_offset": 0,
"end_offset": 10,
"type": "<ALPHANUM>",
"position": 0
}
,
{
"token": "washingt",
"start_offset": 0,
"end_offset": 10,
"type": "<ALPHANUM>",
"position": 0
}
,
{
"token": "washingto",
"start_offset": 0,
"end_offset": 10,
"type": "<ALPHANUM>",
"position": 0
}
,
{
"token": "washington",
"start_offset": 0,
"end_offset": 10,
"type": "<ALPHANUM>",
"position": 0
}
]
}
0

There are 0 best solutions below