gpt4 book ai didi

elasticsearch - ElasticSearch:如何使用edge_ngram并具有真正相关的匹配项以首先显示

转载 作者:行者123 更新时间:2023-12-02 22:29:57 26 4
gpt4 key购买 nike

我是Elasticsearch的新手,我正在尝试开发一个电子商务搜索,以向用户推荐5〜10个匹配产品。

由于它可以在用户键入时正常工作,因此我们在官方文档中发现使用edge_ngram并使其有效。但是,当我们搜寻进行测试时,结果并非预期。如下面的示例所示(在我们的测试中)

Searching example

如图中所示,术语“Furadeira”(电钻)的结果在电钻本身之前返回附件。如何改善结果?我猜想,即使在字符串中找到匹配项的顺序也会对我有帮助。

因此,这是我到目前为止的代码:

//PUT example

{
"settings": {
"number_of_shards": 1,
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 20
},
"portuguese_stop": {
"type": "stop",
"stopwords": "_portuguese_"
},
"portuguese_stemmer": {
"type": "stemmer",
"language": "light_portuguese"
}

},
"analyzer": {
"portuguese": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"portuguese_stop",
"portuguese_stemmer"
]
},
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
}
}

/* mapping */
//PUT /example/products/_mapping
{
"products": {
"properties": {
"name": {
"type": "text",
"analyzer": "autocomplete",
"search_analyzer": "standard"
}
}
}
}


/* Search */
//GET /example/products/_search
{
"query" : {
"query_string": {
"query" : "furadeira",
"type" : "most_fields", // Tried without this aswell
"fields" : [
"name^8",
"model^10",
"manufacturer^4",
"description"
]
}
}
}

/* Product example */
// PUT example/products/38313
{
"name": "FITA VEDA FRESTA (ESPUMA 4503) 12X5 M [ H0000164055 ]",
"description": "Caracteristicas do produto:Ve…Diminui ruidos indesejaveis.",
"price":21.90,
"product_id": 38313,
"image": "http://placehold.it/200x200",
"quantity": 92,
"width": 20.200,
"height": 1.500,
"length": 21.500,
"weight": 0.082,
"model": "167083",
"manufacturer": "3M DO BRASIL"
}


提前致谢。

最佳答案

您可以将查询增强为所谓的 bool(boolean) 查询,该查询在must子句中包含现有查询,但在should子句中具有一个完全匹配的附加查询(不使用ngrammed字段)。如果查询与should子句匹配,它将得分更高。

请参阅bool query文档。

关于elasticsearch - ElasticSearch:如何使用edge_ngram并具有真正相关的匹配项以首先显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44831868/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com