public function setPostFilter(AbstractQuery $filter) { return $this->setParam('post_filter', $filter); }
/** * @group functional */ public function testIndicesQuery() { $docs = array(new Document(1, array('color' => 'blue')), new Document(2, array('color' => 'green')), new Document(3, array('color' => 'blue')), new Document(4, array('color' => 'yellow'))); $index1 = $this->_createIndex(); $index1->addAlias('indices_query'); $index1->getType('test')->addDocuments($docs); $index1->refresh(); $index2 = $this->_createIndex(); $index2->addAlias('indices_query'); $index2->getType('test')->addDocuments($docs); $index2->refresh(); $boolQuery = new Query\BoolQuery(); $boolQuery->addMustNot(new Term(array('color' => 'blue'))); $indicesQuery = new Indices($boolQuery, array($index1->getName())); $boolQuery = new Query\BoolQuery(); $boolQuery->addMustNot(new Term(array('color' => 'yellow'))); $indicesQuery->setNoMatchQuery($boolQuery); $query = new Query(); $query->setPostFilter($indicesQuery); // search over the alias $index = $this->_getClient()->getIndex('indices_query'); $results = $index->search($query); // ensure that the proper docs have been filtered out for each index $this->assertEquals(5, $results->count()); foreach ($results->getResults() as $result) { $data = $result->getData(); $color = $data['color']; if ($result->getIndex() === $index1->getName()) { $this->assertNotEquals('blue', $color); } else { $this->assertNotEquals('yellow', $color); } } }