php 创建es 索引,elasticsearch创建索引时的一些选项问题

我想用elasticsearch为博客的文章做站内搜索,后台用的php。

文章表articles的全部字段如下:

id title content user_id created_at updated_at

现在我想为文章表的title字段、content字段、updated_at字段,共三个字段创建索引。

下面是我参照elasticsearch-php客户端的官方文档写的创建索引blog和创建类型article的demo,分词用到了ik分词。

其中有些选项不太清楚什么意思,具体问题在下面代码中(有4个),请大神帮解答一下,谢谢。

$params = [

'index' => 'blog',

'body' => [

'settings' => [

'number_of_shards' => 1,

'number_of_replicas' => 0,

'analysis' => [

'filter' => [

//1、这里的两个shingle应该改成article吗?

'shingle' => [

'type' => 'shingle'

]

],

//2、char_filter里面内容表示什么意思?包括pre_negs和post_negs。

'char_filter' => [

'pre_negs' => [

'type' => 'pattern_replace',

'pattern' => '(\\w+)\\s+((?i:never|no|nothing|nowhere|noone|none|not|havent|hasnt|hadnt|cant|couldnt|shouldnt|wont|wouldnt|dont|doesnt|didnt|isnt|arent|aint))\\b',

'replacement' => '~$1 $2'

],

'post_negs' => [

'type' => 'pattern_replace',

'pattern' => '\\b((?i:never|no|nothing|nowhere|noone|none|not|havent|hasnt|hadnt|cant|couldnt|shouldnt|wont|wouldnt|dont|doesnt|didnt|isnt|arent|aint))\\s+(\\w+)',

'replacement' => '$1 ~$2'

]

],

//3、analyzer的内容需要怎么修改吗?

'analyzer' => [

'blog' => [

'type' => 'custom',

'tokenizer' => 'standard',

'filter' => ['lowercase', 'stop', 'kstem']

]

]

]

],

'mappings' => [

'article' => [

"_all" => [

"analyzer" => "ik_max_word",

"search_analyzer" => "ik_max_word",

"term_vector" => "no",

"store" => "false"

],

'properties' => [

'title' => [

'type' => 'string',

'store' => 'no',

'term_vector' => 'with_positions_offsets',

'analyzer' => 'ik_max_word',

'search_analyzer' => 'ik_max_word',

'include_in_all' => 'true',

'boost' => 9

],

'content' => [

'type' => 'string',

'store' => 'no',

'term_vector' => 'with_positions_offsets',

'analyzer' => 'ik_max_word',

'search_analyzer' => 'ik_max_word',

'include_in_all' => 'true',

'boost' => 8

],

//4、时间只是用来在搜索的时候排序使用,下面的选项该怎么填写?

'updated_at' => [

'type' => '',

'store' => '',

'term_vector' => '',

'analyzer' => '',

'search_analyzer' => '',

'include_in_all' => '',

'boost' =>

]

]

]

]

]

];

$client->indices()->create($params);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值