e search index.php,php操作elastcisearch使用ik分词做搜索,搜索结果总为空

问题描述

php操作elastcisearch使用分词做搜索,搜索结果总为空

bVbqCRc?w=1445&h=137

bVbqCRv?w=1490&h=548

问题出现的环境背景及自己尝试过哪些方法

相关代码

// 请把代码文本粘贴到下方(请勿用图片代替代码)

/**

Created by PhpStorm.

User: wph

Date: 2019/3/29

Time: 11:17

*/

namespace AppHttpControllerApi;

use ElasticsearchClientBuilder;

use AppModelEsEsClient;

use EasySwooleCoreComponentDi;

class Test extends Base

{

//建立索引

public function createIndex(){

$esclient = EsClient::getInstance()->esClient;

$params = [

'index' => 'index',

];

$res = $esclient->indices()->create($params);

return $this->writeJson(200,'OK',$res);

}

public function createMap()

{

$esclient = EsClient::getInstance()->esClient;

$params = [

'index' => 'index',

'type' => 'fulltext',

'body' => [

'properties' => [

'content' => [

'type' => 'text', // 字符串型

'analyzer'=>'ik_max_word', //ik_max_word 最细粒度拆分 ik_smart最粗粒度拆分

'search_analyzer'=> 'ik_max_word'

]

]

]

];

$res = $esclient->indices()->putMapping($params);

return $this->writeJson(200,"OK",$res);

}

public function addData()

{

$esclient = EsClient::getInstance()->esClient;

$params = [

'index' => 'index',

'type' => 'fulltext',

'body' => [

'contents' =>'中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首' ,

]

];

$res = $esclient->index($params);

$this->writeJson(200,'OK',$res);

}

public function search()

{

$esclient = EsClient::getInstance()->esClient;

$search_params = [

'index' => 'index',

'type' => 'fulltext',

'body' => [

'query' => [

'match' => [                //必须完全匹配

'content' =>  '中国'

]]

$res = $esclient->search($search_params);

var_dump($res);

$this->writeJson(200,'OK',$res);

}

}

从创建索引 index 到添加数据 ,再到搜索全是php操作,使用ik分词做全文检索就搜索不到想要结果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值