I use FOSElasticaBundle to handle the search. Everything works fine when I have the same level of nesting. However, when I have two levels of nesting results that should correspond to the innermost nest, they do not return (for example, a search for the category “xx” does produce results, but a search for “yy” of the brand is not and should).
Here is my fos_elastica configuration:
fos_elastica: clients: default: { host: localhost, port: 9200 } indexes: my_index: client: default types: product: mappings: title: { boost: 1 } articleNumber: ~ introductionDateSearch: { type: integer } delistingDateSearch: { type: integer } deleted: { type: boolean } category: type: "nested" properties: name: { boost: 1 } brand: type: "nested" properties: name: { boost: 1 } persistence: driver: orm model: MyBundle\Entity\Product provider: ~ finder: ~ listener: ~
And my request handler:
public function searchForKeyword($keyword, AbstractUser $user) { $this->setFilters($user); $keyword = trim($keyword); if ($keyword !== '') { $mainQuery = new \Elastica\Query\Bool(); $mainProductQuery = new \Elastica\Query\Bool(); //searching in Product title $productQuery = new \Elastica\Query\Text(); $productQuery->setFieldQuery('title', $keyword); $productQuery->setFieldParam('title', 'boost', 5); $productQuery->setFieldParam('title', 'type', 'phrase_prefix'); //searching in Product articleNumber $articleNumberQuery = new \Elastica\Query\Text(); $articleNumberQuery->setFieldQuery('articleNumber', $keyword); $articleNumberQuery->setFieldParam('articleNumber', 'boost', 5); $articleNumberQuery->setFieldParam('articleNumber', 'type', 'phrase_prefix'); //searching in Category name $categoryQuery = new \Elastica\Query\Text(); $categoryQuery->setFieldQuery('name', $keyword); $categoryQuery->setFieldParam('name', 'boost', 3); $categoryQuery->setFieldParam('name', 'type', 'phrase_prefix'); $nestedCategoryProductQuery = new \Elastica\Query\Nested(); $nestedCategoryProductQuery->setPath('category'); $nestedCategoryProductQuery->setQuery($categoryQuery); //searching in Brand name $brandQuery = new \Elastica\Query\Text(); $brandQuery->setFieldQuery('name', $keyword); $brandQuery->setFieldParam('name', 'boost', 3); $brandQuery->setFieldParam('name', 'type', 'phrase_prefix'); $nestedBrandCategoryQuery = new \Elastica\Query\Nested(); $nestedBrandCategoryQuery->setPath('category.brand'); $nestedBrandCategoryQuery->setQuery($brandQuery); $mainProductQuery->addShould($productQuery); $mainProductQuery->addShould($articleNumberQuery); $mainProductQuery->addShould($nestedCategoryProductQuery); $mainProductQuery->addShould($nestedBrandCategoryQuery); $mainQuery->addMust($mainProductQuery); $esFilteredQuery = new \Elastica\Query\Filtered($mainQuery, $this->filters); } else { $esFilteredQuery = new \Elastica\Query\Filtered(new \Elastica\Query\MatchAll(), $this->filters); } $this->query = new \Elastica\Query(); $this->query->setQuery($esFilteredQuery); }
How is $nestedBrandCategoryQuery to $mainProductQuery ?
Thank you for your help! GTB