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