# Autocomplete for City name with departure city as context

**URL:** <https://discuss.elastic.co/t/autocomplete-for-city-name-with-departure-city-as-context/160001>\
**Category:** Elasticsearch\
**Created:** [December 8, 2018, 10:17am UTC](https://discuss.elastic.co/t/autocomplete-for-city-name-with-departure-city-as-context/160001 "2018-12-08T10:17:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnbenz13](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johnbenz13/32/38591_2.png) [@johnbenz13](https://discuss.elastic.co/u/johnbenz13)\
**Post date:** [December 8, 2018, 10:17am UTC](https://discuss.elastic.co/t/autocomplete-for-city-name-with-departure-city-as-context/160001/1 "2018-12-08T10:17:37Z")

</div>

Hi I'm trying to create an autocomplete suggester for a travel website. You can enter a "From City" (New York, Chicago, Los Angeles, etc...) and then a "To City". ![46](https://us1.discourse-cdn.com/elastic/original/3X/6/7/67b08f9497ee378e14187b2375f55b124924b112.png)  
I don't have any problem having Completion Suggester working for each separate box, but this gets more complicated when I want to return the "To City" according to the "From City".  
I explain, we have a list of popular routes with score:

- New York to Chicago = 10
- New York to Boston = 8
- etc...

If somebody has already selected "New York" as "From City" when he's looking for the "To City" on top of the Completion Suggester I would like to have the results ordered by the score of the popular route.  
I tried to map city as the following but I can't add the score. Any idea of how to integrate the score in my query?

The index:

{  
settings: {  
"analysis": {  
"filter": {  
"autocomplete\_filter": {  
"type": "edge\_ngram",  
"min\_gram": 2,  
"max\_gram": 20  
},  
"shingle\_filter": {  
"type": "shingle",  
"max\_shingle\_size": 3  
}  
},  
"analyzer": {  
"autocomplete": {  
"type": "custom",  
"tokenizer": "standard",  
"filter": [  
"lowercase",  
"shingle\_filter"  
]  
}  
}  
}  
}  
}

The Mapping

```
{
properties: {
  city: { type: 'text'},
  station: {type: 'text'},
  country: { type: 'text'},
  countryCode: { type: 'text'},
  countrySlug: { type: 'text'},
  stationSlug: {type: 'text'},
  citySlug: {type: 'text'},
  name_suggest: {
    type: 'completion',
    analyzer: 'autocomplete',
    search_analyzer: 'standard',
    contexts: [
      {
        name: 'location_type',
        type: 'category',
      },
      {
        name: 'from_city',
        type: 'category',
      },
    ],
  },
},

```

}

---

<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:** [January 5, 2019, 10:17am UTC](https://discuss.elastic.co/t/autocomplete-for-city-name-with-departure-city-as-context/160001/2 "2019-01-05T10:17:43Z")

</div>

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