sexlog / elasticsearch-query-builder
Installs: 8 871
Dependents: 0
Suggesters: 0
Security: 0
Stars: 10
Watchers: 3
Forks: 3
Open Issues: 0
Requires
- elasticsearch/elasticsearch: v8.14.0
- monolog/monolog: 2.9.2
Requires (Dev)
- phpunit/phpunit: 9.*
- dev-master
- 2.0.1
- 2.0.0
- 1.4.0
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.7
- 1.1.6
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.0
- dev-php-74-support
- dev-elastic-upgrade
- dev-poc-att
- dev-fix-null-fields
- dev-test
- dev-fix-prepare-fields
- dev-fix-php83
- dev-php83-support
- dev-fix-404-exception
- dev-add-getById-function
- dev-change-elasticsearch-version
- dev-definition-column-geo-distance
This package is not auto-updated.
Last update: 2025-01-07 19:28:31 UTC
README
This is a library to query data from ElasticSearch. I have just started the development of this library and there is a lot to be done.
My aim is to communicate with ElasticSearch in a fully object oriented way.
Examples
Basic query
$hosts = ['10.0.0.10:9200']; $index = 'products'; $client = \Elasticsearch\ClientBuilder::fromConfig(['hosts' => $hosts]); $elasticSearch = new ElasticSearch\ElasticSearch($index, $client); // SELECT * FROM products WHERE product_name = 'ElasticSearch' LIMIT 4 $query = new ElasticSearch\Query(); $query->where('product_name', 'ElasticSearch'); $elasticSearch->setQuery($query) ->take(4) ->get(); // Paging results $results = $elasticSearch->page(1) ->get(); $results = $elasticSearch->page(2) ->get();
Query with a Filter
/* * SELECT id, product_name, price, updated_at * FROM products * WHERE product_name LIKE 'car%' AND category = 3 LIMIT 20 OFFSET 0 */ $query = new ElasticSearch\Query(); $query->wildcard('product_name', 'car*'); $filter = new ElasticSearch\Filter(); $filter->where('category', 3); // You should always use the take method before paging $elasticSearch->select('id, product_name, price, updated_at') ->setQuery($query) ->setFilter($filter) ->take(20) ->page(0) ->get(); // Paging $results = $elasticSearch->page(1) ->get();
Logging
$hosts = ['10.0.0.10:9200']; $index = 'products'; $client = \Elasticsearch\ClientBuilder::fromConfig(['hosts' => $hosts]); $elasticSearch = new ElasticSearch\ElasticSearch($index, $client); $errorHandler = new \Monolog\Handler\StreamHandler('elastic.log', \Monolog\Logger::ERROR); $logger = new \Monolog\Logger('elastic'); $logger->pushHandler($errorHandler); $elasticSearch->setLogger($logger);