How to perform nested queries with Elastica Search and Symfony2

前端 未结 2 1325
说谎
说谎 2021-02-11 03:13

I have a recipe entity which have some tags (many to many mapping) and I want to search recipes by tags.

Here\'s my Recipe entity:

/**
 * @ORM\\Entity
 *         


        
2条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-11 03:22

    Indeed, you forgot to define the Filtered query.

    This should work :

    $nested->setQuery(new \Elastica\Query\Term(array('name' => array('value' => $searchText))));
    $nested->setPath('tags');
    $query_part->addShould($nested);
    
    $query = new \Elastica\Query\Filtered($query_part/*, $filters // in case you had other filters*/);
    return $this->find($query);
    

提交回复
热议问题