Created
January 5, 2020 04:06
-
-
Save byhbt/e5a7b859c2fc89883bcee9995ed9d431 to your computer and use it in GitHub Desktop.
How to use elastica
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Cách 1: Sử dụng EsHelper để build query | |
*/ | |
$esHelper = new EsHelper(); | |
$term = $esHelper->createTerm('company_id', -1); | |
$boolQuery = $esHelper->createBoolQuery(); | |
$boolQuery->addMust($term); | |
$query = $esHelper->createQuery(); | |
$query->setQuery($boolQuery); | |
// dump($query->toArray()); | |
/** | |
* Cách 2: Sử dụng trực tiếp Elatica để build query | |
*/ | |
$elasticaQueryType = new \Elastica\Query\Term(); | |
$elasticaQueryType->setTerm('company_id', -1); | |
$elasticaQueryBool = new \Elastica\Query\BoolQuery(); | |
$elasticaQueryBool->addMust($elasticaQueryType); | |
$query = new \Elastica\Query(); | |
$query->setQuery($elasticaQueryBool); | |
/** | |
* Query | |
*/ | |
/** @var \Elastica\ResultSet $rs */ | |
$rs = Elastica::addIndex('magneto') | |
->addType('candidate') | |
->search($query); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment