Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/dpb587/elasticsearch-in-memory-filter.php

Reuse elasticsearch filters for matching in-memory arrays.
https://github.com/dpb587/elasticsearch-in-memory-filter.php

Last synced: 24 days ago
JSON representation

Reuse elasticsearch filters for matching in-memory arrays.

Awesome Lists containing this project

README

        

# elasticsearch-in-memory-filter.php

Reuse elasticsearch filters for matching in-memory arrays.

## Example

```php
use DPB\ElasticsearchInMemoryFilter as _;

$doc = [
'name' => 'Dublin Pizza Company',
'type' => 'restaurant',
'categories' => [
[ 'id' => 12345,
'name' => 'pizza' ] ] ];

$esFilter = [
'and' => [
[ 'term' => [
'type' => 'restaurant' ] ],
[ 'nested' => [
'path' => 'categories',
'filter' => [
'term' => [
'categories.name' => 'pizza' ] ] ] ] ] ];

$filter = _\Transformer::transform($esFilter);

var_export($filter->match($doc));
// true

$filter = new _\Filter\TermFilter([ 'type' => 'restaurant' ]);

var_export($filter->match($doc));
// true

var_export($filter->match([ 'type' => 'cafe' ]));
// false
```

## License

[MIT License](./LICENSE)