Robert M
Robert M

Reputation: 1

Symfony Doctrine with FosElastic how to search from ORM and Elastic together?

For example

my entity has fields:

id (int)

title (text) (stored also in elastic)

content (text) (stored also in elastic)

categoryId (int)

status (int)

and i want to search text from title,content i use

//RepositoryManagerInterface $finder
$results = $finder->getRepository(Offer::class)->find('AUDI A6 C6 2.0');

when i want search in database example by categoryId

$offers = $this->getDoctrine()->getRepository(Offer::class)->customOfferQueryBuilderWithResult(['categoryId'=>5]);

how to search it together? do I have to store categoryId also in elastic?

Upvotes: 0

Views: 321

Answers (1)

Lukas Zmoginas
Lukas Zmoginas

Reputation: 86

Try this:

//Repository method

/**
 * @param int $id
 * @return Query
 */
public function getByOfferId(int $id): Query
{
    $terms = new Terms('categoryId', [$id]);
    $boolQuery = (new BoolQuery())->addMust($terms);
    return (new Query())->setQuery($boolQuery);
}

Upvotes: 0

Related Questions