Ubuntu16.04下安装elasticsearch+kibana实现php客户端的中文分词
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Ubuntu16.04下安装elasticsearch+kibana实现php客户端的中文分词,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3534字,纯文字阅读大概需要6分钟。
内容图文
1.下载安装elasticsearch和kibana
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.4.2.deb dpkg -i elasticsearch-5.4.2.deb wget https://artifacts.elastic.co/downloads/kibana/kibana-5.4.2-amd64.deb dpkg -i kibana-5.4.2-amd64.deb
2.安装中文分词插件,包括elasticsearch原生的中文分词icu和smartcn,以及第三方中文分词ik、拼音分词pinyin、繁简转换stconvert。
/usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-icu /usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-smartcn
wget https://github.com/medcl/elasticsearch-analysisi-stconvert/releases/download/v5.4.2/elasticsearch-analysisi-stconvert-5.4.2.zip
/usr/share/elasticsearch/bin/elasticsearch-plugin install file:///{path}/elasticsearch-analysis-stconvert-5.4.2.zip
wget https://github.com/medcl/elasticsearch-analysisi-ik/releases/download/v5.4.2/elasticsearch-analysis-ik-5.4.2.zip
unzip elasticsearch-analysis-ik-5.4.2.zip -d /usr/share/elasticsearch/plugins/analysis-ik
wget https://github.com/medcl/elasticsearch-analysisi-pinyin/releases/download/v5.4.2/elasticsearch-analysis-pinyin-5.4.2.zip
unzip elasticsearch-analysis-pinyin-5.4.2.zip -d /usr/share/elasticsearch/plugins/analysis-pinyin
3.启动服务器
service elasticsearch start
service kibana start
4.在kibana的Dev Tools中测试,地址为http://localhost:5601
大体上可以将Elasticsearch理解为一个RDBMS(关系型数据库,比如MySQL),那么index 就相当于数据库实例,type可以理解为表。
Mapping定义了type中的诸多字段的数据类型以及这些字段如何被Elasticsearch处理,比如一个字段是否可以查询以及如何分词等。
analyzer=char_filter+tokenizer+token_filter按顺序执行
PUT /stconvert/ { "settings" : { "analysis" : { "analyzer" : { "tsconvert" : { "tokenizer" : "tsconvert" } "tsconvert_icu" : { "tokenizer" : "icu_tokenizer", "char_filter" : ["tsconvert"], } }, "tokenizer" : { "tsconvert" : { "type" : "stconvert", "delimiter" : "#", "keep_both" : false, "convert_type" : "t2s" } }, "char_filter" : { "tsconvert" : { "type" : "stconvert", "delimiter" : "#", "keep_both" : false, "convert_type" : "t2s" } } } }, "mappings":{ "test":{ "properties":{ "title": { "type":"text", "analyzer":"tsconvert_icu" } } } } } } GET /stconvert/_analyze?pretty { "analyzer": "tsconvert_icu", "text": ["狼藉藉口,北京国際電視檯"] } PUT /stconvert/test/1 { "title":"狼藉藉口,北京国际电视台" } PUT /stconvert/test/2 { "title":"狼藉借口,中央國際電視檯" } GET /stconvert/test/_search { "query":{ "match":{ "title":"国際" } } }
5.安装composer, elasticsearch-php和php的curl扩展
php -r "copy(‘https://install.phpcomposer.com/installer‘, ‘composer-setup.php‘);" php composer-setup.php php composer.phar require "elasticsearch/elasticsearch": "~5.0" apt-get install php-curl
在/etc/php/7.0/fpm/php.ini中去掉 ;extension=php_curl.dll 前的分号,重启服务
6.测试php搜索elasticsearch
<?php require ‘vendor/autoload.php‘; use Elasticsearch\ClientBuilder; $hosts=[‘localhost‘]; $client = ClientBuilder::create() // Instantiate a new ClientBuilder ->setHosts($hosts) // Set the hosts ->build(); // Build the client object$searchParams = [ ‘index‘ => ‘stconvert‘, ‘type‘ => ‘test‘, ‘body‘ => [ ‘query‘ => [ ‘match‘ => [ ‘title‘ => ‘国際‘ ] ] ] ]; try { $results = $client->search($searchParams); } catch (Elasticsearch\Common\Exceptions\TransportException $e) { $previous = $e->getPrevious(); if ($previous instanceof Elasticsearch\Common\Exceptions\MaxRetriesException) { echo "Max retries!"; } } print_r($results); ?>
elasticsearch的帮助文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html
elasticsearch-php的帮助文档:https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html
原文:http://www.cnblogs.com/luminary/p/7159787.html
内容总结
以上是互联网集市为您收集整理的Ubuntu16.04下安装elasticsearch+kibana实现php客户端的中文分词全部内容,希望文章能够帮你解决Ubuntu16.04下安装elasticsearch+kibana实现php客户端的中文分词所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。