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)