作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用elasticsearch创建热门搜索查询。
我想从elasticsearch表中匹配category_name
,brand_name
和title
。匹配项应为词组以及with或condition。
我的查询:
$query = [
"bool" => [
"must" => [
["match" => ["is_published" => 1]],
[
"multi_match" => [
"query" => $searchKey,
"fields" => ["category_name", "brand_name", "title"]
]
],
[
'nested' => [
'path' => 'category_with_in_title.parent_cat',
'query' => [
'bool' => [
'must' => [
['match' => [
'category_with_in_title.parent_cat.status' => 1,
]],
],
],
],
],
],
[
'nested' => [
'path' => 'brand',
'query' => [
'bool' => [
'must' => [
'match' => [
'brand.approved_status' => 1,
],
],
],
],
],
],
[
'nested' => [
'path' => 'default_product_low_price_with_seller.seller_detail',
'query' => [
'bool' => [
'must' => [
'match' => [
'default_product_low_price_with_seller.seller_detail.approve_status' => 1,
],
],
],
],
],
],
[
'nested' => [
'path' => 'default_product_low_price_with_seller',
'query' => [
'bool' => [
'must' => [
'match' => [
'default_product_low_price_with_seller.status' => 1,
],
],
],
],
],
],
],
],
];
multi_match
,但如何在此查询中使用pharse?我必须写整个词来搜索。
category_name = Tops
的记录
最佳答案
您可以使用match_phrase_prefix,它与match_phrase相同,不同之处在于允许在文本的最后一项上进行前缀匹配。
您需要做的就是将"type": "phrase_prefix"
添加到multi_match
查询中,如下所示:
"multi_match" => [
"query" => $searchKey,
"type": "phrase_prefix",
"fields" => ["category_name", "brand_name", "title"]
]
关于php - 如何在Elasticsearch中编写全局查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36569635/
我是一名优秀的程序员,十分优秀!