如何使用Elastica
进行WHERE categoryId = 1 OR categoryId = 2
查询?我正在做这个,但我得到了0 result
:
$query = new \Elastica\Query();
$boolOr = new \Elastica\Filter\BoolOr();
$boolOr->addFilter(new \Elastica\Filter\Term(array('categoryId' => '1')));
$boolOr->addFilter(new \Elastica\Filter\Term(array('categoryId' => '2')));
$filtered = new \Elastica\Query\Filtered(new \Elastica\Query\MatchAll(), $boolOr);
$query->setQuery($filtered);
$products = $type->search($query)->getResults();
发布于 2015-07-07 08:46:38
下面是一个有效的示例:
$index = $this->_createIndex();
$type = $index->getType('test');
$doc1 = new Document('', array('categoryId' => 1));
$doc2 = new Document('', array('categoryId' => 2));
$doc3 = new Document('', array('categoryId' => 3));
$type->addDocument($doc1);
$type->addDocument($doc2);
$type->addDocument($doc3);
$index->refresh();
$boolOr = new \Elastica\Filter\BoolOr();
$boolOr->addFilter(new \Elastica\Filter\Term(array('categoryId' => '1')));
$boolOr->addFilter(new \Elastica\Filter\Term(array('categoryId' => '2')));
$resultSet = $type->search($boolOr);
您不需要使用筛选和匹配查询。可以在以下位置找到工作示例:https://github.com/ruflin/Elastica/pull/887/files
https://stackoverflow.com/questions/30831031
复制相似问题