gpt4 book ai didi

elasticsearch - 如何强制mult_match中的某些字段具有完全匹配

转载 作者:行者123 更新时间:2023-12-03 01:48:41 25 4
gpt4 key购买 nike

我正在尝试将产品列表的标题与已知产品的数据库匹配。我的第一个想法是将已知产品及其元数据放入elasticsearch中,并尝试使用multi_match找到最佳匹配。我当前的查询是这样的:

{
"query": {
"multi_match" : {
"query": "Men's small blue cotton pants SKU123",
"fields": ["sku^2","title","gender","color", "material","size"],
"type" : "cross_fields"
}
}
}

问题是有时它会退回颜色错误的产品。有没有一种方法可以修改上面的查询,以便仅对索引中具有颜色字段等于查询字符串中存在的单词的项目进行评分?我正在使用elasticsearch 5.1。

最佳答案

如果要让Elasticsearch仅对满足特定条件的项目评分,则需要在过滤器上下文中使用terms query
由于terms query不会分析您的查询,因此您必须自己做。简单的方法是使用空格和小写标记,并生成如下所示的查询:

{
"query": {
"bool": {
"filter": {
"terms": {
"color": ["men's", "small", "blue", "cotton", "pants", "sku123"]
}
},
"must": {
"multi_match": {
"query": "Men's small blue cotton pants SKU123",
"fields": [
"sku^2",
"title",
"gender",
"material",
"size"
],
"type": "cross_fields"
}
}
}
}
}

关于elasticsearch - 如何强制mult_match中的某些字段具有完全匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42060348/

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