【发布时间】:2019-11-24 16:54:55
【问题描述】:
我有带有属性的产品。例如“名称”、“品牌”、“颜色”、“类别”、“尺寸”。当我按短语搜索产品时(例如“black jack puma”),除了与“brand”=“puma”、“color”=“black”、“category”=“jacket”或“name”= “黑色彪马夹克”,我也有偏配的产品。我的查询是:
'match' => [
'message' => [
'query' => "black puma jacket"
'operator' => 'and'
]
]
我也试过这个查询:
'multi_match' => [
'fields' => [
'brand',
'color',
'name'
],
'query' => 'puma black jacket',
]
我的查询有什么问题?
更新:
我的映射:
'brand' => [
'type' => 'string',
'fields' => [
'keyword' => [
'type' => 'string',
'analyzer' => 'slug',
'index_options' => 'docs',
],
'raw' => [
'type' => 'string',
'analyzer' => 'format',
]
]
],
'color' => [
'type' => 'string',
'fields' => [
'keyword' => [
'type' => 'string',
'analyzer' => 'slug',
'index_options' => 'docs',
],
'raw' => [
'type' => 'string',
'analyzer' => 'format',
]
]
],
'category' => [
'type' => 'string',
'fields' => [
'keyword' => [
'type' => 'string',
'analyzer' => 'slug',
'index_options' => 'docs',
],
'raw' => [
'type' => 'string',
'analyzer' => 'format',
]
]
],
'category_id' => [
'type' => 'integer',
],
'store_id' => [
'type' => 'integer',
],
'size' => [
'type' => 'string',
'fields' => [
'keyword' => [
'type' => 'string',
'analyzer' => 'slug',
'index_options' => 'docs',
],
'raw' => [
'type' => 'string',
'analyzer' => 'format',
]
]
],
'material' => [
'type' => 'string',
'fields' => [
'keyword' => [
'type' => 'string',
'analyzer' => 'slug',
'index_options' => 'docs',
],
'raw' => [
'type' => 'string',
'analyzer' => 'format',
]
]
],
'type' => [
'type' => 'string',
'fields' => [
'keyword' => [
'type' => 'string',
'analyzer' => 'slug',
'index_options' => 'docs',
],
'raw' => [
'type' => 'string',
'analyzer' => 'format',
]
]
],
'volume' => [
'type' => 'string',
'fields' => [
'keyword' => [
'type' => 'string',
'analyzer' => 'slug',
'index_options' => 'docs',
],
'raw' => [
'type' => 'string',
'analyzer' => 'format',
]
]
],
'price' => [
'type' => 'float',
],
'desc' => [
'type' => 'string',
],
'sku' => [
'type' => 'string',
'index' => 'not_analyzed'
],
'picture' => [
'type' => 'string',
'index' => 'not_analyzed'
]
];
【问题讨论】:
-
尝试查询:{ bool : { must: { match: { text: 'black puma jack'} } } }
-
尝试查询:{ bool : { must: { match: { text: 'black puma jack'} } } }
-
不。此查询返回空结果
-
请提供一个示例,说明您正在尝试实现的目标以及与您的映射相关的详细信息。谢谢
-
@AssaelAzran,我放置了我的映射。我的目标是仅搜索属性或名称与我的查询字符串匹配的项目。如果我搜索“黑色夹克”,我只想查看存在“黑色”和“夹克”的项目(无论在哪里 - 产品属性或名称),并且只传递“黑色”或“夹克”匹配的项目。如果我在 DB 10 中有颜色为“黑色”的项目和 5 个类型或类别为“夹克”的项目,并且只有 2 个颜色为“黑色”并输入“夹克”的项目,搜索结果必须只包含 2 个项目。跨度>
标签: elasticsearch