I'm trying to create and autocomplete of destinations and i want to boost results by a popularity integer field.
i'm trying with this function_score query
'query' => [
'function_score' => [
'query' => [
"bool" => [
"should" => [
[
"multi_match"=>[
"query"=>$text,
"fields"=>[
"destination_name_*"
],
"type"=>"most_fields",
"boost" => 2
]
],
[
"multi_match"=>[
"query"=>$text,
"fields"=>[
"destination_name_*"
],
"fuzziness" => "1",
"prefix_length"=> 2
]
],
[
"multi_match"=>[
"query"=>$text,
"fields"=>[
"destination_name_*.exact"
],
"boost" => 2
]
]
]
]
],
'field_value_factor' => [
'field'=>'popularity'
]
],
],
Mapping & settings:
'settings' => [
'analysis' => [
'filter' => [
'ngram_filter' => [
'type' => 'edge_ngram',
'min_gram' => 2,
'max_gram' => 20,
]
],
'analyzer' => [
'ngram_analyzer' => [
'type' => 'custom',
"tokenizer" => "standard",
'filter' => ['lowercase', 'ngram_filter'],
]
]
],
],
'mappings' =>[
'doc' => [
"properties"=> [
"destination_name_en"=> [
"type"=> "text",
"term_vector"=> "yes",
"analyzer"=> "ngram_analyzer",
"search_analyzer"=> "standard",
"fields" => [
"exact" => [
"type" => "text",
"analyzer" => "standard"
]
]
],
"destination_name_es"=> [
"type"=> "text",
"term_vector"=> "yes",
"analyzer"=> "ngram_analyzer",
"search_analyzer"=> "standard",
"fields" => [
"exact" => [
"type" => "text",
"analyzer" => "standard"
]
]
],
"destination_name_pt"=> [
"type"=> "text",
"term_vector"=> "yes",
"analyzer"=> "ngram_analyzer",
"search_analyzer"=> "standard",
"fields" => [
"exact" => [
"type" => "text",
"analyzer" => "standard"
]
]
],
"popularity"=> [
"type"=> "integer",
]
]
]
]
I set to 10 the value of popularity in cancún and when I start I write "ca" the first option is cancún. This work as expected ...
But the problem comes when I try to find other city where the popularity value is 0 like Puerto Vallarta. When I write "Puerto Va" I obtain the following results:
1.-Val d´Aosta 2.-Puerto Lopez 3.-Bristol - VA and many others ... (But not puerto vallarta)
It is important to emphasize that whitout the funtion score and field_value_factor this query works how to expect (return in the first position puerto vallarta.)
I want to add the capacity of boost popular cities with a integer value.
Any suggestion?
Thanks!