2017 © Pedro Peláez
 

library elasticsearch

crcms elasticsearch module

image

crcms/elasticsearch

crcms elasticsearch module

  • Tuesday, July 17, 2018
  • by hiword
  • Repository
  • 0 Watchers
  • 42 Stars
  • 479 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 5 Versions
  • 17 % Grown

The README.md

Crcms Elasticsearch

Latest Stable Version License StyleCI, (*1)

Version Matrix

Elasticsearch Version crcms/elasticsearch Branch
>= 7.0 master(beta unstable)
>= 6.0 1.*
>= 5.0, < 6.0 0.*

Install

You can install the package via composer:, (*2)

composer require crcms/elasticsearch

Please install if you want to use the latest version dev-master, (*3)

Use

Non-Laravel framework

// select config path
$config = require 'search.php';
$builder = Factory::builder($config);

Laravel

Modify config / app.php If the version is less <= 5.5, (*4)

'providers' => [
    CrCms\ElasticSearch\LaravelServiceProvider::class,
]

If you'd like to make configuration changes in the configuration file you can pubish it with the following Aritsan command:, (*5)

php artisan vendor:publish --provider="CrCms\ElasticSearch\LaravelServiceProvider"

Quickstart

Create

$builder->index('index')->type('type')->create([
    'key' => 'value'
]);

// return a collection
$builder->index('index')->type('type')->createCollection([
    'key' => 'value'
]);

Update

$builder->index('index')->type('type')->update([
    'key' => 'value1'
]);

Delete

$builder->index('index')->type('type')->delete($result->_id);

Select


$builder = $builder->index('index')->type('type'); //SQL:select ... where id = 1 limit 1; $result = $builder->whereTerm('id',1)->first(); //SQL:select ... where (key=1 or key=2) and key1=1 $result = $builder->where(function (Query $inQuery) { $inQuery->whereTerm('key',1)->orWhereTerm('key',2) })->whereTerm('key1',1)->get();

More

skip / take, (*6)

$builder->take(10)->get(); // or limit(10)
$builder->offset(10)->take(10)->get(); // or skip(10)

term query, (*7)

$builder->whereTerm('key',value)->first();

match query, (*8)

$builder->whereMatch('key',value)->first();

range query, (*9)

$builder->whereBetween('key',[value1,value2])->first();

where in query, (*10)

$builder->whereIn('key',[value1,value2])->first();

logic query, (*11)

$builder->whereTerm('key',value)->orWhereTerm('key2',value)->first();

nested query, (*12)

$result = $builder->where(function (Builder $inQuery) {
    $inQuery->whereTerm('key',1)->orWhereTerm('key',2)
})->whereTerm('key1',1)->get();

Available conditions

public function select($columns): self
public function where($column, $operator = null, $value = null, $leaf = 'term', $boolean = 'and'): self
public function orWhere($field, $operator = null, $value = null, $leaf = 'term'): self
public function whereMatch($field, $value, $boolean = 'and'): self
public function orWhereMatch($field, $value, $boolean = 'and'): self
public function whereTerm($field, $value, $boolean = 'and'): self
public function whereIn($field, array $value)
public function orWhereIn($field, array $value)
public function orWhereTerm($field, $value, $boolean = 'or'): self
public function whereRange($field, $operator = null, $value = null, $boolean = 'and'): self
public function orWhereRange($field, $operator = null, $value = null): self
public function whereBetween($field, array $values, $boolean = 'and'): self

```php public function whereNotBetween($field, array $values): self, (*13)

```php
public function orWhereNotBetween(string $field, array $values): self

```php public function whereExists($field, $boolean = 'and'): self, (*14)

```php
public function whereNotExists($field, $boolean = 'and'): self
public function orWhereBetween($field, array $values): self
public function orderBy(string $field, $sort): self
public function scroll(string $scroll): self
public function aggBy($field, $type): self
public function select($columns): self

Result Method

public function get(): Collection
public function paginate(int $page, int $perPage = 15): Collection
public function first()
public function byId($id)
public function byIdOrFail($id): stdClass
public function chunk(callable $callback, $limit = 2000, $scroll = '10m')
public function create(array $data, $id = null, $key = 'id'): stdClass
public function update($id, array $data): bool
public function delete($id)
public function count(): int

Log

//open log
$builder->enableQueryLog();

//all query log
dump($build->getQueryLog());

//last query log
dump($build->getLastQueryLog());

Elastisearch object

getElasticSearch() // or search()

If you want to expand more, you can use this method, call https://github.com/elastic/elasticsearch-php, (*15)

Other

For more examples, please see test cases https://github.com/crcms/elasticsearch/blob/master/tests/BuildTest.php, (*16)

License

MIT license, (*17)

The Versions

17/07 2018

dev-master

9999999-dev https://github.com/crcms/elasticsearch

crcms elasticsearch module

  Sources   Download

MIT

The Requires

 

laravel php elasticsearch crcms

04/04 2018

1.0.1

1.0.1.0 https://github.com/crcms/elasticsearch

crcms elasticsearch module

  Sources   Download

MIT

The Requires

 

laravel php elasticsearch crcms

28/03 2018

1.0.0

1.0.0.0 https://github.com/crcms/elasticsearch

crcms repository extends laravel

  Sources   Download

MIT

The Requires

 

laravel php elasticsearch crcms

21/12 2017

0.0.2

0.0.2.0 https://github.com/crcms/elasticsearch

crcms repository extends laravel

  Sources   Download

MIT

The Requires

 

laravel php elasticsearch crcms

16/10 2017

0.0.1

0.0.1.0 https://github.com/crcms/elasticsearch

crcms repository extends laravel

  Sources   Download

MIT

The Requires

 

laravel php elasticsearch crcms