Ubuntu16.04 install Elasticsearch+kibana to implement the Chinese word segmentation of PHP Client

Source: Internet
Author: User
Tags kibana

1. Download and install Elasticsearch and 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.debdpkg-i kibana-5.4. 2-amd64.deb

2. Install Chinese word breaker, including elasticsearch native Chinese word segmentation ICU and SMARTCN, and third-party Chinese word segmentation ik, pinyin word segmentation pinyin, simplified conversion stconvert.

/usr/share/elasticsearch/bin/elasticsearch-pluginInstallanalysis-ICU/usr/share/elasticsearch/bin/elasticsearch-pluginInstallanalysis-SMARTCN
wgetHttps//GITHUB.COM/MEDCL/ELASTICSEARCH-ANALYSISI-STCONVERT/RELEASES/DOWNLOAD/V5.4.2/ Elasticsearch-analysisi-stconvert-5.4.2.zip
/usr/share/elasticsearch/bin/elasticsearch-pluginInstallFile:///{path}/elasticsearch-analysis-stconvert-5.4.2.zip
wgetHttps//Github.com/medcl/elasticsearch-analysisi-ik/releases/download/v5.4.2/elasticsearch-analysis-ik-5.4.2.zip
Unzipelasticsearch-analysis-ik-5.4.2.Zip-d/usr/share/elasticsearch/plugins/analysis-IK
wgetHttps//Github.com/medcl/elasticsearch-analysisi-pinyin/releases/download/v5.4.2/elasticsearch-analysis-pinyin-5.4.2.zip
Unzipelasticsearch-analysis-pinyin-5.4.2.Zip-d/usr/share/elasticsearch/plugins/analysis-pinyin

3. Start the server

Service Elasticsearch StartService Kibana start

4. Test in Kibana's dev tools with the address http://localhost:5601

Generally, you canElasticsearchUnderstood as an RDBMS (relational database, like MySQL), thenIndexis equivalent to a database instance, type can be understood as a table.
MappingDefines the data types of many fields in the type and how those fields areElasticsearchProcessing, such as whether a field can query and how to participle.
Analyzer=char_filter+tokenizer+token_filter executed sequentially

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": ["the excuse of the mess, Beijing International TV pool table"]}put/stconvert/test/1{    "title":"the excuse of the mess, Beijing International television"}put/stconvert/test/2{    "title":"A messy excuse, central international TV pool table"}get/stconvert/test/_search{"Query":{        "Match":{            "title":"Guo International"        }    }}

5. Install composer, elasticsearch-php and PHP curl Extensions

" copy (' Https://install.phpcomposer.com/installer ', ' composer-setup.php '); " php composer-"elasticsearch/elasticsearch""~5.0 " Apt Install Php-curl

To be removed from the/etc/php/7.0/fpm/php.ini ; Extension=php_curl.dll Pre-semicolon, restart service

6. Test PHP Search Elasticsearch

<?PHPrequire' Vendor/autoload.php '; UseElasticsearch\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 ' = ' International '            ]        ]    ]]; Try{ $results =$client->search ($searchParams);} Catch(elasticsearch\common\exceptions\transportexception$e) {    $previous=$e-getprevious (); if($previousinstanceof Elasticsearch\common\exceptions\maxretriesexception) {        Echo"Max retries!"; }}Print_r($results);?>

Elasticsearch's Help document: Https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html
Elasticsearch-php's Help document: Https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html

Ubuntu16.04 install Elasticsearch+kibana to implement the Chinese word segmentation of PHP Client

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.