gpt4 book ai didi

php - 如何在Elasticsearch中编写全局查询?

转载 作者:行者123 更新时间:2023-12-02 23:00:05 25 4
gpt4 key购买 nike

我想使用elasticsearch创建热门搜索查询。

我想从elasticsearch表中匹配category_namebrand_nametitle。匹配项应为词组以及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的记录

如果我写“tops”或“top”或“to”,我想要结果。但是现在我必须写“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/

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