弹性搜索提取错误

时间:2017-09-22 10:43:31

标签: php elasticsearch

我有以下代码。

<?php

$params = [
    'index' => $this->client->getIndex(),
    'type' => $this->client->getType(),
    "from" => 0, "size" => 1000,
    "scroll" => "1m",
    'body' => [
        "query" => [
            "multi_match" => [
                "fields" => ["prod_name", "prod_seo_name"],
                "type" => "best_fields",
                "query" => $query
            ],
        ],
    ],
];

如果我搜索“三星手机”,它也会返回其他结果。我希望它只显示特定的记录。任何人都可以指导我在哪里做错了。

结果:

[19] => Array
            (
                [prod_id] => 12186
                [lang_id] => 1
                [manuf_id] => 5
                [cat_type_id] => 2
                [cat_id] => 3
                [network_id] => 0
                [comp_group_id] => 0
                [prod_name] => Samsung J700 mobile phone Silver Unlocked Sim Free
                [prod_short_name] => 
                [prod_color] => 0
                [prod_seo_name] => simfree-samsung-j700-silver-unlocked
)
 [999] => Array
            (
                [prod_id] => 12074
                [lang_id] => 1
                [manuf_id] => 7
                [cat_type_id] => 2
                [cat_id] => 3
                [network_id] => 0
                [comp_group_id] => 0
                [prod_name] => LG KU990i Viewty Mobile Phone Unlocked Sim Free
                [prod_short_name] => 
                [prod_color] => 0
                [prod_seo_name] => simfree-lg-viewty-unlocked
)

我能做些什么来解雇'='查询而不是'LIKE'查询

1 个答案:

答案 0 :(得分:1)

type的{​​{1}}更改为使用词组搜索而不是简单匹配的multi_matchphrase

phrase_prefix

请参阅:https://www.elastic.co/guide/en/elasticsearch/reference/5.5/query-dsl-multi-match-query.html#type-phrase