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".
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',
},
],
},
},
}