salamtam / elasticsearch-loop-php
for Looping data from Elasticsearch
Installs: 4 636
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 2
Open Issues: 0
Type:vcs
Requires
README
for Looping data from Elasticsearch
#Usage
##Initial setup
-
Install composer.
curl -s http://getcomposer.org/installer | php
-
Create composer.json containing:
{ "require" : { "salamtam/elasticsearch-loop-php" : "^1.4" } }
-
Run
./composer.phar install
-
Keep up-to-date:
./composer.phar update
##Example 1
Query with URL
require_once __DIR__ . "/vendor/autoload.php"; use ElasticsearchLoopPHP\ElasticsearchLoop; /* set connection elasticsearch */ $url = "localhost:9200"; /* set index name and type */ $params = [ 'index' => 'index_name', 'type' => 'index_type', 'body' => [ 'query' => [ 'match_all' => [] ] ] ]; /* callback function */ $callback = function($response) { foreach ($response['hits']['hits'] as $item) { print_r($item); } }; /* set query with url */ $client = new ElasticsearchLoop($url); $client->getElasticsearch($params, $callback);
##Example 2
Query with basic authentication
require_once __DIR__ . "/vendor/autoload.php"; use ElasticsearchLoopPHP\ElasticsearchLoop; /* set connection elasticsearch */ $user = "root"; $pass = ""; $host = "localhost"; $port = "9200"; /* set index name and type */ $params = [ 'index' => 'index_name', 'type' => 'index_type', 'body' => [ 'query' => [ 'match_all' => [] ] ] ]; /* callback function */ $callback = function($response) { foreach ($response['hits']['hits'] as $item) { print_r($item); } }; /* set query with host, user, pass and port */ $client = new ElasticsearchLoop($host, $user, $pass, $port); $client->getElasticsearch($params, $callback);