FOSElasticaBundle multiple subqueries

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

+6
source share
1 answer

FOSElasticaBundle uses the Elastica library. Therefore, this should not be a FOSElasticaBundle problem.

See http://elastica.io/ for more information on Lib. In my experience, you cannot do anything with Elastica if it is supported by Elasticsearch. Even if there is no Mapper in Elastica, just use the Raw Array query ( http://elastica.io/example/raw-array-query.html ) to create the desired query.

0
source

All Articles