2017 © Pedro Peláez
 

library simple-elasticsearch-client

Simple ElasticSearch Library.

image

ienaga/simple-elasticsearch-client

Simple ElasticSearch Library.

  • Friday, June 1, 2018
  • by ienaga
  • Repository
  • 2 Watchers
  • 0 Stars
  • 5,060 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 4 % Grown

The README.md

SimpleElasticSearchClient

ElasticSearch Simple Library for PHP, (*1)

ElasticSearch Version

  • 2.3.x
  • 5.1.x

Build Status, (*2)

Latest Stable Version Total Downloads Latest Unstable Version License, (*3)

Search

Case - 1

SELECT * FROM `INDEX_NAME`.`TYPE_NAME` WHERE `statue` = 1;
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

Case - 2

SELECT * FROM `INDEX_NAME`.`TYPE_NAME` WHERE (`user_id` = 1 OR `user_id` = 2);
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

Case - 3

SELECT * FROM `INDEX_NAME`.`TYPE_NAME` WHERE `status` != 0;
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

Case - 4

SELECT * FROM `INDEX_NAME`.`TYPE_NAME` WHERE `status` BETWEEN 0 AND 100;
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

Case - 5

SELECT * FROM `INDEX_NAME`.`TYPE_NAME` WHERE `status` > 100;

```php use \SimpleElasticSearch\Client;, (*4)

$client = new new Client([ "end_point" => "URL" ]);, (*5)

$result = $client ->setIndex("INDEX_NAME") ->setType("TYPE_NAME") ->createFilter() // filter search start ->operator("status", 100, "gt") ->attach() // filter search end ->search(); // execute search, (*6)


# Result ```php 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; } }

Data Create

use \SimpleElasticSearch\Client;

$client = new new Client([
    "end_point" => "URL"
]);

$query = [
    "status"  => 0,
    "price"   => 100,
    "user_id" => 1,
];

$client
    ->setIndex("index name")
    ->setType("type name")
    ->setBody($query)
    ->create();

Data Update Plural

use \SimpleElasticSearch\Client;

$client = new new \SimpleElasticSearch\Client([
    "end_point" => "URL"
]);

$result = $client
    ->setIndex("index name")
    ->setType("type name")
    ->createFilter()
    ->addAnd("user_id", $userId)
    ->attach()
    ->search();

if ($result->isFound()) {
    foreach ($result as $hit) {

        $hit->status = 1;

        $client
            ->setIndex("index name")
            ->setType("type name")
            ->setId($hit["_id"])
            ->setBody($hit->getSource())
            ->update();
    }
}

Data Update Singular

use \SimpleElasticSearch\Client;

$client = new new \SimpleElasticSearch\Client([
    "end_point" => "URL"
]);

$result = $client
    ->setIndex("index name")
    ->setType("type name")
    ->setId("id name")
    ->get();

if ($result->isFound()) {
    $result->status = 1;

    $client
        ->setIndex($result->getIndex())
        ->setType($result->getType())
        ->setId($result->getId())
        ->setBody($result->getSource())
        ->update();
}

Data Delete

use \SimpleElasticSearch\Client;

$client = new new \SimpleElasticSearch\Client([
    "end_point" => "URL"
]);

$client
    ->setIndex("index name")
    ->setType("type name")
    ->setId("id name")
    ->delete();

The Versions

01/06 2018

dev-master

9999999-dev https://github.com/ienaga/SimpleElasticSearchClient

Simple ElasticSearch Library.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Toshiyuki Ienaga

library elasticsearch aws

01/06 2018

1.0.0

1.0.0.0 https://github.com/ienaga/SimpleElasticSearchClient

Simple ElasticSearch Library.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Toshiyuki Ienaga

library elasticsearch aws