PHP code example of ienaga / simple-elasticsearch-client
1. Go to this page and download the library: Download ienaga/simple-elasticsearch-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ienaga / simple-elasticsearch-client example snippets
use \SimpleElasticSearch\Client;
$client = new new Client([
"end_point" => "URL"
]);
$result = $client
->setIndex("INDEX_NAME")
->setType("TYPE_NAME")
->createFilter() // filter search start
->addAnd("status", $status)
->attach() // filter search end
->search(); // execute search
use \SimpleElasticSearch\Client;
$client = new new Client([
"end_point" => "URL"
]);
$result = $client
->setIndex("INDEX_NAME")
->setType("TYPE_NAME")
->createFilter() // filter search start
->addOr("user_id", 1)
->addOr("user_id", 2)
->attach() // filter search end
->search(); // execute search
use \SimpleElasticSearch\Client;
$client = new new Client([
"end_point" => "URL"
]);
$result = $client
->setIndex("INDEX_NAME")
->setType("TYPE_NAME")
->createFilter() // filter search start
->addNot("status", 0)
->attach() // filter search end
->search(); // execute search
use \SimpleElasticSearch\Client;
$client = new new Client([
"end_point" => "URL"
]);
$result = $client
->setIndex("INDEX_NAME")
->setType("TYPE_NAME")
->createFilter() // filter search start
->between("status", 0, 100)
->attach() // filter search end
->search(); // execute search
use \SimpleElasticSearch\Client;
$client = new new Client([
"end_point" => "URL"
]);
$result = $client
->setIndex("INDEX_NAME")
->setType("TYPE_NAME")
->createFilter() // filter search start
->operator("status", 100, "gt")
->attach() // filter search end
->search(); // execute search
use \SimpleElasticSearch\Client;
$client = new new Client([
"end_point" => "URL"
]);
$result = $client
->setIndex("index name")
->setType("type name")
->createFilter() // filter search start
->addAnd("status", $status) // match case
->setFrom($offset) // offset
->setSize($limit) // limit
->addSort("price", $sort) // sort
->setAggregation("user_id") // group by
->attach() // filter search end
->search(); // execute search
// found
if ($result->isFound()) {
// ArrayAccess, Iterator, Countable
foreach ($result as $hit) {
// Result Singular
// $hit->getIndex();
// $hit->getType();
// $hit->getId();
// $hit->property;
}
}