PHP code example of saxulum / saxulum-elasticsearch-querybuilder
1. Go to this page and download the library: Download saxulum/saxulum-elasticsearch-querybuilder 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/ */
saxulum / saxulum-elasticsearch-querybuilder example snippets
use Saxulum\ElasticSearchQueryBuilder\Node\ArrayNode;
use Saxulum\ElasticSearchQueryBuilder\Node\FloatNode;
use Saxulum\ElasticSearchQueryBuilder\Node\IntNode;
use Saxulum\ElasticSearchQueryBuilder\Node\ObjectNode;
use Saxulum\ElasticSearchQueryBuilder\Node\StringNode;
$qb = ObjectNode::create()
->add('query', ObjectNode::create()
->add('bool', ObjectNode::create()
->add('must', ObjectNode::create()
->add('term', ObjectNode::create()
->add('user', StringNode::create('kimchy'))
)
)
->add('filter', ObjectNode::create()
->add('term', ObjectNode::create()
->add('tag', StringNode::create('tech'))
)
)
->add('must_not', ObjectNode::create()
->add('range', ObjectNode::create()
->add('age', ObjectNode::create()
->add('from', IntNode::create(10))
->add('to', IntNode::create(20))
)
)
)
->add('should', ArrayNode::create()
->add(ObjectNode::create()
->add('term', ObjectNode::create()
->add('tag', StringNode::create('wow'))
)
)
->add(ObjectNode::create()
->add('term', ObjectNode::create()
->add('tag', StringNode::create('elasticsearch'))
)
)
)
->add('minimum_should_match', IntNode::create(1))
->add('boost', FloatNode::create(1.1))
)
);
echo $qb->json(true);