PHP code example of myappin / elasticsearchpredicate

1. Go to this page and download the library: Download myappin/elasticsearchpredicate 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/ */

    

myappin / elasticsearchpredicate example snippets


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

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

$_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);

$_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');