gesof / elastic-search
Elastic Search utility
1.1.0
2023-04-27 13:18 UTC
Requires
- php: ^7.0||^8.0
- elasticsearch/elasticsearch: ^8.0
This package is auto-updated.
Last update: 2025-04-27 18:44:45 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 />';
}