hello @byronvoorbach, sorry for my late response, but i need to try many things and read more about elasticsearch before to response this message.
I followed many of your recommendations and now i have an autocomplete with better results.
These are my mappings:
Hotel Mapping:
$params = [
'index' => 'hotels',
'body' => [
'settings' => [
'analysis' => [
'filter' => [
'ngram_filter' => [
'type' => 'edge_ngram',
'min_gram' => 2,
'max_gram' => 20,
]
],
'analyzer' => [
'ngram_analyzer' => [
'type' => 'custom',
"tokenizer" => "standard",
"tokenizer" => "standard",
'filter' => ['lowercase', 'ngram_filter'],
'stopwords' => ['the', "and", "&", "hotel", "all inclusive", "resort"]
]
]
],
],
'mappings' =>[
'doc' => [
"properties"=> [
"name"=> [
"type"=> "text",
"term_vector"=> "yes",
"analyzer"=> "ngram_analyzer",
"search_analyzer"=> "standard",
],
"popularity"=> [
"type"=> "integer",
]
]
]
]
]
];
Destination_mapping:
$params = [
'index' => 'destinations',
'body' => [
'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",
],
"destination_name_es"=> [
"type"=> "text",
"term_vector"=> "yes",
"analyzer"=> "ngram_analyzer",
"search_analyzer"=> "standard",
],
"destination_name_pt"=> [
"type"=> "text",
"term_vector"=> "yes",
"analyzer"=> "ngram_analyzer",
"search_analyzer"=> "standard",
],
"popularity"=> [
"type"=> "integer",
]
]
]
]
]
];
And this is my search_query:
$params = array(
'index' => ['destinations','hotels'],
"size" => 20,
'body' => array(
'sort' => array(
array('popularity' => array('order' => "desc")),
"_score"
),
'query' => array(
"bool" => array(
"should" => array(
array(
"multi_match" => array(
"type" => "best_fields",
"query" => $text,
"fields" => ["destination_name_*^3","name"],
"fuzziness"=>1
)
),
array(
"term" => array(
"destination_name_*" => array(
"value" => $text,
"boost" => 10
)
)
),
),
)
)
)
);
The idea of my autocomplete is the follow:
1.-Show first the hotels/destinations with a higest popularity value
2.-Show second the exact text match (show first the destinations and then the hotels)
3.-Allow to the users to make some mistakes, por example: Cancn, vancun, tancun => Cancun (for this reason I use fuzziniess)
4.-The search can be made with many languajes, for that razon I use the "destination_name_*
"
I was reading about the obsolete "type" in ES6.x and decided not to use the type, however keep the 2 indexes because I think they are very different objects.
Maybe i dont use the best scheme to obtain the results that i want. I you have any comment or suggestion in general I'll happy to hear it.
Thanks for your time.