myappin/elasticsearchpredicate

ElasticSearch nested predicate generator

5.6.4 2022-01-28 10:33 UTC

README

is simple PHP API for ElasticSearch. It simulates Zend-Db predicates.

Please create issue while missing something or finding a bug

Install

composer: HERE OR

git clone https://github.com/myappin/ElasticSearchPredicate.git

Usage

Adding predicates addPredicate(PredicateInterface $predicate), andPredicate(PredicateInterface $predicate), orPredicate(PredicateInterface $predicate), and(PredicateInterface $predicate), or(PredicateInterface $predicate)

Basic predicates

$_client = new Client();
$_search = $_client->search();

$_search->limit(10)->order('_uid', 'asc')->predicate->Term('name', 'SomeName')->or->Term('price', 1000);

Nesting

$_client = new Client();
$_search = $_client->search();

$_search->limit(10)->order('_uid', 'asc')->predicate->nest()->Term('name', 'SomeName')->or->Term('name', 'SomeOtherName')->unnest()->Term('price', 1000);

Boosting

$_client = new Client();
$_search = $_client->search();

$_search->limit(10)->order('_uid', 'asc')->predicate->andPredicate((new Term('name', 'SomeName'))->boost(2))->or->Term('name', 'SomeOtherName');
//or
$_search->limit(10)->order('_uid', 'asc')->predicate->Term('name', 'SomeName', ['boost' => 2])->or->Term('name', 'SomeOtherName');

Nested objects, Ranges, Score Functions and more and more