Elasticsearch 0.90.5 Install and use php client


You can start follow by these step

  1. download elasticsearch-0.90.5 from http://www.elasticsearch.org and extract to htdocs [Required php 5.3.6++]
  2. run elasticsearch with command line , example
    $ /Applications/XAMPP/htdocs/elasticsearch-0.90.5/bin/elasticsearch
  3. try go to http://localhost:9200 you can see the result same I show you an image below 
    that mean the elasticsearch is already work.
  4. install elasticsearch management plug-in with commandline for monitoring your elasticsearch server and information , example
    $ /Applications/XAMPP/htdocs/elasticsearch-0.90.5/plugin -install mobz/elasticsearch-head
  5. try to go http://localhost:9201/_plugin/head/ you can see elasticsearch management

  6. Create new index by click the “New Index” button

    index name(reference name) : ใส่ชื่อเรียกข้อมูลชุดนั้นๆ เช่น member เป็นต้น(คล้ายๆกับชื่อ database)
    number of shards : เป็นการกระจาย node หรือพูดง่ายๆ ก็คือจะให้มันเก็บบน server กี่เครื่อง
    number of replicas : เป็นตัว master/slave ตัว backup นั้นเอง หากมีตัวไหนตาย มันก็ยังสามารถทำงานได้อยู่


    You can see 10 number of shards [0-9] and you can run elasticsearch server on step 2 again for make the slave server


    You can see master/slave port 9200,9201. Now you finish install and run elasticsearch server.

  7. Next, How to download and use PHP API client for search,insert,update and delete. First go to the root of elasticsearch directory on command line and run
    curl -s http://getcomposer.org/installer | php
  8. Create composer.json containing
    {
    "require": {
    "elasticsearch/elasticsearch": "~0.4"
    }
    }
  9. Run
    ./composer.phar install

    or

    php composer.phar install

    for install PHP API
    after you install successful you can see vendor directory

  10. Keep up-to-date
    ./composer.phar update

    or

    php composer.phar update
  11. last I show you the script for example use the PHP API client script
  12. after you insert new data to your_index you can see your new data on elasticsearch management at “Browser tab”

 

Related posts:

This entry was posted in knowledge, php, technology. Bookmark the permalink.