Elasticsearch PHP API Usage (i)

Source: Internet
Author: User

Prerequisite: Install Elasticsearch (host:192.168.1.10) on the server

        Http://192.168.1.10:9200?_search?pretty

1: Install PHP elasticsearch extensions (using the composer method)

1.1 Download Composer.phar Package (see composer installation software http://www.cnblogs.com/amuge/p/5998985.html)

1.2 Composer.json

{

     "require" : {          "elasticsearch/elasticsearch" "[email protected]"        }     }

1.3 php Composer.phar Install will automatically find Composer.json this configuration file, download this extension. When the download is complete, a new vendor directory is added to the currently running directory (indicating successful download of the elasticsearch-php extension)

2: Copy the vendor directory to the project's third-party extension directory (for example: I am using the YII framework. I will copy the vendor to the Application/protected/vendor/elasticsearch directory)

3: Test

Require_once (__dir__. ‘/.. /vendor/elasticsearch/autoload.php '); $hosts = Array (' 192.168.1.10 '); $client = Elasticsearch\clientbuilder::create ( )->sethosts ($hosts)->build (); $client = $this->getelasticclient (); $params = Array (    ' index ' = = ') Website ',    ' type ' = ' blog ',    ' body ' = = Array (' query ' = = Array ('            match ' = = Array ('                _id ' + 1,           )))    ; $rtn = $client->search ($params); Echo ' <pre> ';p rint_r ($RTN); Echo ' </pre> ' ;d ie (' FILE: '. __file__. ‘; Line: '. __LINE__);

4: Results

Official Document: Https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_quickstart.html

Elasticsearch PHP API Usage (i)

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.