gesof / elastic-search
Elastic Search utility
Installs: 65
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/gesof/elastic-search
Requires
- php: ^7.0||^8.0
- elasticsearch/elasticsearch: ^8.0
This package is auto-updated.
Last update: 2025-09-27 19:27:00 UTC
README
$text = 'UFOs over China';
$hosts = [
'localhost:9200',
];
$client = \Elastic\Elasticsearch\ClientBuilder::create()
->setHosts($hosts)
->build();
$qb = new \Gesof\ElasticSearch\QueryBuilder($client);
$qb
->setTable('posts')
->orderBy('_id', 'desc')
;
$andX = $qb->expr()->andX();
$andX->add($qb->expr()->eq('is_completed', TRUE));
$andX->add($qb->expr()->gt('view_count', 10));
$orX = $qb->expr()->orX();
$orX->add($qb->expr()->matchText('title', $text));
$orX->add($qb->expr()->matchText('description', $text));
$andX->add($orX);
$qb->where($andX);
$qb
->setMaxResults(10)
->setFirstResult(0)
;
$resultCount = $qb->getQuery()->count()->getCount();
$documents = $qb->getQuery()->search()->getDocuments();
foreach ($documents as $document) {
// echo $document->title . '<br />';
}