Я создал индекс категории с предложением о завершении, и он не ведет себя так, как я ожидал бы.Elasticsearch не соответствует точной строке
curl -XPUT http://localhost:9200/categories/category/_mapping -d '{
"category" : {
"properties" : {
"categoryDescription" : {
"type" : "string"
},
"suggest" : {
"type" : "completion",
"analyzer" : "simple",
"search_analyzer" : "simple",
"payloads" : true
}
}
}
}'
У меня есть категория проиндексированы для «мексиканский Продуктовый магазин» и когда я ищу для этой строки я получаю ноль хитов и только предположить, результат:
{
"query":{
"fuzzy":{
"categoryDescription":{
"value":"mexican grocery store"
}
}
},
"from":0,
"size":20,
"suggest":{
"category-suggest":{
"text":"mexican grocery store",
"completion":{
"field":"suggest","fuzzy":{"fuzziness":2}
}
}
}
}
{
"took":19,
"timed_out":false,
"_shards":{"total":5,"successful":5,"failed":0},
"hits":{
"total":0,"max_score":null,"hits":[]
},
"suggest":{
"category-suggest":[
{
"text":"mexican grocery store",
"offset":0,
"length":21,
"options":[
{
"text":"Mexican Grocery Store",
"score":1.0,
"payload":{"id":5915028960051200}
}
]
}
]
}
}
Не только я получаю ноль хитов для точного совпадения, но когда я печатаю строку «мексиканский», список категорий со словом «медицинский» в ней перечисляется перед «мексиканскими» категориями, которые для меня тоже не имеют никакого смысла.
{
"query":{
"fuzzy":{
"categoryDescription":{
"value":"mexican"
}
}
},
"from":0,
"size":20,
"suggest":{
"category-suggest":{
"text":"mexican",
"completion":{
"field":"suggest","fuzzy":{"fuzziness":2}
}
}
}
}
{
"took":11,
"timed_out":false,
"_shards":{
"total":5,
"successful":5,
"failed":0
},
"hits":{
"total":25,
"max_score":3.8085938,
"hits":[
{
"_index":"categories",
"_type":"category",
"_id":"4993638215974912",
"_score":3.8085938,
"_source":{
"id":4993638215974912,
"categoryDescription":"Medical Spa",
"suggest":{
"input":["Medical Spa"],
"output":"Medical Spa",
"payload":{"id":4993638215974912}}}},
{"_index":"categories","_type":"category","_id":"6401013099528192","_score":3.8085938,"_source":{"id":6401013099528192,"categoryDescription":"Medical School","suggest":{"input":["Medical School"],"output":"Medical School","payload":{"id":6401013099528192}}}},{"_index":"categories","_type":"category","_id":"4712163239264256","_score":3.4429123,"_source":{"id":4712163239264256,"categoryDescription":"Medical Examiner","suggest":{"input":["Medical Examiner"],"output":"Medical Examiner","payload":{"id":4712163239264256}}}},{"_index":"categories","_type":"category","_id":"5978800634462208","_score":3.4429123,"_source":{"id":5978800634462208,"categoryDescription":"Medical Center","suggest":{"input":["Medical Center"],"output":"Medical Center","payload":{"id":5978800634462208}}}},{"_index":"categories","_type":"category","_id":"5415850681040896","_score":3.4429123,"_source":{"id":5415850681040896,"categoryDescription":"Medical Clinic","suggest":{"input":["Medical Clinic"],"output":"Medical Clinic","payload":{"id":5415850681040896}}}},{"_index":"categories","_type":"category","_id":"4852900727619584","_score":2.75433,"_source":{"id":4852900727619584,"categoryDescription":"Medical Billing Service","suggest":{"input":["Medical Billing Service"],"output":"Medical Billing Service","payload":{"id":4852900727619584}}}},{"_index":"categories","_type":"category","_id":"5352079006629888","_score":2.4411354,"_source":{"id":5352079006629888,"categoryDescription":"Mexican Restaurant","suggest":{"input":["Mexican Restaurant"],"output":"Mexican Restaurant","payload":{"id":5352079006629888}}}},{"_index":"categories","_type":"category","_id":"5915028960051200","_score":2.143557,"_source":{"id":5915028960051200,"categoryDescription":"Mexican Grocery Store","suggest":{"input":["Mexican Grocery Store","shop"],"output":"Mexican Grocery Store","payload":{"id":5915028960051200}}}},{"_index":"categories","_type":"category","_id":"6392217006505984","_score":2.0527549,"_source":{"id":6392217006505984,"categoryDescription":"Latin American Restaurant","suggest":{"input":["Latin American Restaurant"],"output":"Latin American Restaurant","payload":{"id":6392217006505984}}}},{"_index":"categories","_type":"category","_id":"5149768867119104","_score":2.0527549,"_source":{"id":5149768867119104,"categoryDescription":"Occupational Medical Physician","suggest":{"input":["Occupational Medical Physician"],"output":"Occupational Medical Physician","payload":{"id":5149768867119104}}}},{"_index":"categories","_type":"category","_id":"5157465448513536","_score":2.0527549,"_source":{"id":5157465448513536,"categoryDescription":"Central American Restaurant","suggest":{"input":["Central American Restaurant"],"output":"Central American Restaurant","payload":{"id":5157465448513536}}}},{"_index":"categories","_type":"category","_id":"6479078425100288","_score":2.0527549,"_source":{"id":6479078425100288,"categoryDescription":"American Football Field","suggest":{"input":["American Football Field"],"output":"American Football Field","payload":{"id":6479078425100288}}}},{"_index":"categories","_type":"category","_id":"4789129053208576","_score":1.9529084,"_source":{"id":4789129053208576,"categoryDescription":"Mexican Goods Store","suggest":{"input":["Mexican Goods Store","shop"],"output":"Mexican Goods Store","payload":{"id":4789129053208576}}}},{"_index":"categories","_type":"category","_id":"5275113192685568","_score":1.9138902,"_source":{"id":5275113192685568,"categoryDescription":"Medical Laboratory","suggest":{"input":["Medical Laboratory"],"output":"Medical Laboratory","payload":{"id":5275113192685568}}}},{"_index":"categories","_type":"category","_id":"5838063146106880","_score":1.7436681,"_source":{"id":5838063146106880,"categoryDescription":"Medical Group","suggest":{"input":["Medical Group"],"output":"Medical Group","payload":{"id":5838063146106880}}}},{"_index":"categories","_type":"category","_id":"4649491076481024","_score":1.7436681,"_source":{"id":4649491076481024,"categoryDescription":"American Restaurant","suggest":{"input":["American Restaurant"],"output":"American Restaurant","payload":{"id":4649491076481024}}}},{"_index":"categories","_type":"category","_id":"5458456756617216","_score":1.5311122,"_source":{"id":5458456756617216,"categoryDescription":"Traditional American Restaurant","suggest":{"input":["Traditional American Restaurant"],"output":"Traditional American Restaurant","payload":{"id":5458456756617216}}}},{"_index":"categories","_type":"category","_id":"6183309797228544","_score":1.5311122,"_source":{"id":6183309797228544,"categoryDescription":"Public Medical Center","suggest":{"input":["Public Medical Center"],"output":"Public Medical Center","payload":{"id":6183309797228544}}}},{"_index":"categories","_type":"category","_id":"6706677332049920","_score":1.5311122,"_source":{"id":6706677332049920,"categoryDescription":"Native American Goods Store","suggest":{"input":["Native American Goods Store","shop"],"output":"Native American Goods Store","payload":{"id":6706677332049920}}}},{"_index":"categories","_type":"category","_id":"6119538122817536","_score":1.3949344,"_source":{"id":6119538122817536,"categoryDescription":"Medical Supply Store","suggest":{"input":["Medical Supply Store","shop"],"output":"Medical Supply Store","payload":{"id":6119538122817536}}}}]},"suggest":{"category-suggest":[{"text":"mexican","offset":0,"length":7,"options":[{"text":"Medical Billing Service","score":1.0,"payload":{"id":4852900727619584}},{"text":"Medical Center","score":1.0,"payload":{"id":5978800634462208}},{"text":"Medical Clinic","score":1.0,"payload":{"id":5415850681040896}},{"text":"Medical Examiner","score":1.0,"payload":{"id":4712163239264256}},{"text":"Medical Group","score":1.0,"payload":{"id":5838063146106880}}]}]}}
О, ничего себе! Какое замечательное объяснение. Большое вам спасибо :) Объяснение того, как работает нечеткий запрос, помогает мне лучше понять, как все это работает. Есть ли более эффективная настройка с точки зрения индекса, который я мог бы сделать, чтобы помочь достичь того, чего я ожидаю? –
Я попытался использовать анализатор nGram в какой-то момент, но столкнулся с проблемами, когда у меня была категория Bar и другие категории со словом Bar в них, например, как Barn, и когда пользователь вводил слова «Bar» с Bar в нем появляясь сначала в списке, и снова не будет просто показывать Bar, точное соответствие, в первую очередь. –
nGram имеет аналогичную проблему; он дает те же условия для «Бар» и «Барн», что делает невозможным разграничение между этими двумя. Вот сценарий игры для двух предложений из моего ответа: https: //www.found.no/play/gist/dba4dec7672146946de9c80fb8656e7c - Если вы хотите знать, как вы можете достичь того, чего хотите, лучше спросить новый вопрос, где вы описываете свои цели и задаете прямо этот вопрос. – knutwalker