elasticsearch 模糊查询不分词,实现 mysql like

一、分词

我们可以先来看下啥叫分词,在es中,分词会对关键词进行一个或者几个分隔,比如输入了 隔壁小白,则会查询到 隔壁、小、白、隔、小壁等关键词有关的文档数据。

而使用过mysql的模糊查询的童鞋们,应该都知道,输入了 隔壁小白,则只会出现 隔壁小白123、321淘宝了压抑122、22445淘宝了压抑等相关的数据。它不会对其中的关键词进行分割

二、不分词使用

es对于不分词,其实主要是 match_phrase的使用。我们平时比较多是使用match,这个是会进行分词的


三、先看下使用match 查询结果  

   [6] => Array
                        (
                            [_index] => testindex
                            [_type] => testtype
                            [_id] => P3QqTHcBSzBd54DbdZMl
                            [_score] => 3.9861763
                            [_source] => Array
                                (
                                    [product_name] => 1016隔壁小白287
                                    [rand] => 5082
                                )

                        )

                    [7] => Array
                        (
                            [_index] => testindex
                            [_type] => testtype
                            [_id] => Q3QqTHcBSzBd54DbepOG
                            [_score] => 3.9861763
                            [_source] => Array
                                (
                                    [product_name] => 504隔壁小白1030
                                    [rand] => 5275
                                )

                        )

                    [8] => Array
                        (
                            [_index] => testindex
                            [_type] => testtype
                            [_id] => s3QrTHcBSzBd54DbDZPS
                            [_score] => 3.9861763
                            [_source] => Array
                                (
                                    [product_name] => 801隔壁小白15
                                    [rand] => 4342
                                )

                        )

                    [9] => Array
                        (
                            [_index] => testindex
                            [_type] => testtype
                            [_id] => enQqTHcBSzBd54Dbs5PF
                            [_score] => 3.807864
                            [_source] => Array
                                (
                                    [product_name] => 162隔1壁2小3白4157
                                    [rand] => 5552
                                )

                        )

由此可见搜索 “隔壁小白”  结果出现  “162隔1壁2小3白4157”  “504隔壁小白1030”  

四、使用 match_phrase  进行检索结果如下  

 (
                    [0] => Array
                        (
                            [_index] => testindex
                            [_type] => testtype
                            [_id] => PnQqTHcBSzBd54Dbc5PD
                            [_score] => 7.4503546
                            [_source] => Array
                                (
                                    [product_name] => 579隔壁小白891
                                    [rand] => 6165
                                )

                        )

                    [1] => Array
                        (
                            [_index] => testindex
                            [_type] => testtype
                            [_id] => QnQqTHcBSzBd54DbeZOu
                            [_score] => 7.4503546
                            [_source] => Array
                                (
                                    [product_name] => 928隔壁小白637
                                    [rand] => 9975
                                )

                        )

                    [2] => Array
                        (
                            [_index] => testindex
                            [_type] => testtype
                            [_id] => PHQqTHcBSzBd54DbbZNd
                            [_score] => 4.6551437
                            [_source] => Array
                                (
                                    [product_name] => 77隔壁小白1106
                                    [rand] => 2949
                                )

                        )

                )

 

 

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值