Https://github.com/richardwilly98/elasticsearch-river-mongodb
Https://github.com/mallocator/Elasticsearch-MySQL-River
https://github.com/BioMedCentralLtd/spring-data-elasticsearch-sample-application/blob/master/src/test/ Resources/springcontext-book-test.xml instances
Http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/search.html
http://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#repositories. create-instances.spring
In order to replace the Segmentfault search that now uses less experience, I started the exploration of the previous search engine. Currently preferred is Elasticsearch
Elasticsearch requires a Java environment
Installing Java
sudo aptitude install openjdk-7-jre
Download Elasticsearch
http://www.elasticsearch.org/overview/elkdownloads/
Https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.1.0.deb
Installation
Because my environment is Ubuntu, so directly with its Deb package.
sudo dpkg -i elasticsearch-1.1.0.deb
Start
sudo /etc/init.d/elasticsearch start
JDBC River
For regular or real-time import of data that needs to be searched
Our database is MySQL, so use the official ELASTICSEARCH-RIVER-JDBC
Https://github.com/jprante/elasticsearch-river-jdbc
River JDBC QuickStart
Https://github.com/jprante/elasticsearch-river-jdbc/wiki/Quickstart
Installation
cd /usr/share/elasticsearchsudo /bin/plugin --install river-jdbc --url http://bit.ly/1jyXrR9
If the installation fails, you can download it manually before installing it.
sudo /bin/plugin --install river-jdbc --url file:///tmp/elasticsearch-river-jdbc-1.0.0.1.zip
Create a JDBC River
curl -XPUT ‘localhost:9200/_river/my_jdbc_river/_meta‘ -d ‘{ "type" : "jdbc", "jdbc" : { "url" : "jdbc:mysql://localhost:3306/test", "user" : "root", "password" : "", "sql" : "select * from question", "index" : "question", "type" : "question" }}‘
Test the Import Effect:
curl -XGET ‘localhost:9200/question/_search?pretty&q=*‘
Or
localhost:9200/question/_search?pretty&q=*
The official Chinese word support, but not very accurate, here use MEDCL ik participle
Installing Elasticsearch-analysis-ik
cd /tmpwget https://github.com/medcl/elasticsearch-analysis-ik/archive/master.zipunzip master.zipcd elasticsearch-analysis-ik/
This needs to be packaged into Elasticsearch-analysis-ik-1.2.6.jar with the MVN Package command.
package
Without maven, you can install it.
sudo aptitude install maven
Copy Elasticsearch-analysis-ik-1.2.6.jar to Es_home/plugins/analysis-ik
sudo cp elasticsearch-analysis-ik-1.2.6.jar /usr/share/elasticsearch/plugins/analysis-ik
Copy the IK configuration and dictionaries to Es_home/config
sudo cp -R ik /etc/elasticsearch
Elasticsearch configuration Enable IK
sudo vim /etc/elasticsearch
Add a row to the bottom
index.analysis.analyzer.ik.type : ‘ik‘
Restart Service load Configuration
sudo service elasticsearch restart
Test Word segmentation effect
localhost:9200/question/_analyze?analyzer=ik&pretty=true&text=杭州堆栈科技有限公司
Return
{ "Tokens ":[ { "Token ":"Hangzhou", "Start_offset ":0, "End_offset ":2, "Type ":"Cn_word", "Position ":1}, {"Token ":"Stack", "Start_offset ":2, "End_offset ":4, "Type ":"Cn_word", "Position ":2}, {"Token ":"Technology", "Start_offset ":4, "end_offset": 6," type ": CN_WORD "," position ": 3}, {" token": "Company", " Start_offset ": 6," end_offset ": Span class= "Hljs-value" >10, "type": "Cn_word", "position": 4}]}
Test the official PHP client
The official PHP client is installed via composer
Install composer first
-s http://getcomposer.org/installer | phpsudo mv composer.phar /usr/bin/composer
Generates a Composer.json, writes
{ "require": { "elasticsearch/elasticsearch": "~1.0" }}
Start installation
install --no-dev
After require in the project, you can use the
<?phprequire ‘vendor/autoload.php‘;$client = new Elasticsearch\Client();
Mapping of using Chinese word segmentation ik
$params [' Index '] =' Question ';$params [' type '] =' Question ';$myTypeMapping =Array' _source ' =Array' Enabled ' =True),' _all ' =Array' Indexanalyzer ' =' Ik ',' Searchanalyzer ' =' Ik ',' Term_vector ' =' No ',' Store ' =' false '),' Properties ' =Array' Text ' = =Array' type ' = =' String ',' Term_vector ' =' With_positions_offsets ',' Indexanalyzer ' =' Ik ',' Searchanalyzer ' =' Ik ',' Include_in_all ' =' True ',' Boost ' =8),' Title ' =Array ' type ' = ' string ', ' Term_vector ' = = ' Indexanalyzer ' and ' ik ', ' searchanalyzer ' = ' ik ', ' Include_in_all ' + ' true ', ' boost ' = > 8)); $params [ ' body '][ ' question '] = Span class= "hljs-variable" > $myTypeMapping; $response = $client -> Indices () ->putmapping ( $params);
Test the effect, search for the question content ' PHP framework '
$searchParams = array();$searchParams[‘index‘] = ‘question‘;$searchParams[‘type‘] = ‘question‘;$searchParams[‘body‘][‘query‘][‘match‘][‘text‘] = ‘php框架‘;
Return, take a few
- What is the PHP framework written by Segmentfault? http://segmentfault.com/q/1010000000095152
- Just learn PHP, to introduce the merits and demerits of thinkphp framework http://segmentfault.com/q/1010000000129535
- Is symfony much more powerful than other PHP frameworks?
http://segmentfault.com/q/1010000000095952
- Python framework is numerous, how to grasp the overall? http://segmentfault.com/q/1010000000186319
- What is ORM and how is it used on PHP? http://segmentfault.com/q/1010000000318125
- CodeIgniter framework PHP relies on installation issues http://segmentfault.com/q/1010000000253966
Summarize
The installation and use of Elasticsearch is very simple, and it is also better than the existing search results in the absence of optimized returns.
But the only drawback is that the document is too small compared to SOLR, and many of them give only the most basic examples.
Combination search and so on, you have to ponder and find.
Preliminary study on Elasticsearch