Exemplo n.º 1
1
 /**
  * @group functional
  */
 public function testReverseNestedAggregation()
 {
     $agg = new Nested('comments', 'comments');
     $names = new Terms('name');
     $names->setField('comments.name');
     $tags = new Terms('tags');
     $tags->setField('tags');
     $reverseNested = new ReverseNested('main');
     $reverseNested->addAggregation($tags);
     $names->addAggregation($reverseNested);
     $agg->addAggregation($names);
     $query = new Query();
     $query->addAggregation($agg);
     $results = $this->_getIndexForTest()->search($query)->getAggregation('comments');
     $this->assertArrayHasKey('name', $results);
     $nameResults = $results['name'];
     $this->assertCount(3, $nameResults['buckets']);
     // bob
     $this->assertEquals('bob', $nameResults['buckets'][0]['key']);
     $tags = array(array('key' => 'foo', 'doc_count' => 2), array('key' => 'bar', 'doc_count' => 1), array('key' => 'baz', 'doc_count' => 1));
     $this->assertEquals($tags, $nameResults['buckets'][0]['main']['tags']['buckets']);
     // john
     $this->assertEquals('john', $nameResults['buckets'][1]['key']);
     $tags = array(array('key' => 'bar', 'doc_count' => 1), array('key' => 'foo', 'doc_count' => 1));
     $this->assertEquals($tags, $nameResults['buckets'][1]['main']['tags']['buckets']);
     // susan
     $this->assertEquals('susan', $nameResults['buckets'][2]['key']);
     $tags = array(array('key' => 'baz', 'doc_count' => 1), array('key' => 'foo', 'doc_count' => 1));
     $this->assertEquals($tags, $nameResults['buckets'][2]['main']['tags']['buckets']);
 }
Exemplo n.º 2
0
 protected function getStates()
 {
     $results = [];
     $query = new Elastica\Query();
     $query->setSize(0);
     $agg = new Elastica\Aggregation\Nested('states', 'state');
     $st_terms = new Elastica\Aggregation\Terms('abbrev');
     $st_terms->setField('state.abbrev');
     $st_terms->setOrder('_term', 'asc');
     $st_terms->setSize(0);
     $state_terms = new Elastica\Aggregation\Terms('full');
     $state_terms->setField('state.full');
     $st_terms->addAggregation($state_terms);
     $agg->addAggregation($st_terms);
     $query->addAggregation($agg);
     /* @var $elastica_client Elastica\Client */
     $elastica_client = $this->getServiceLocator()->getServiceLocator()->get('elastica-client');
     try {
         /* @var $response \Elastica\Response */
         $response = $elastica_client->request('usgeodb/locality/_search?query_cache=true', Request::GET, $query->toArray());
         $data = $response->getData();
         $aggregations = isset($data['aggregations']['states']['abbrev']['buckets']) ? $data['aggregations']['states']['abbrev']['buckets'] : [];
         foreach ($aggregations as $aggregation) {
             $key = strtoupper($aggregation['key']);
             $value = ucwords($aggregation['full']['buckets'][0]['key']);
             $results[$key] = $value;
         }
     } catch (\Exception $e) {
     }
     return $results;
 }
 public function testNestedAggregation()
 {
     $agg = new Nested("resellers", "resellers");
     $min = new Min("min_price");
     $min->setField("price");
     $agg->addAggregation($min);
     $query = new Query();
     $query->addAggregation($agg);
     $results = $this->_index->search($query)->getAggregation("resellers");
     $this->assertEquals(4.98, $results['min_price']['value']);
 }
Exemplo n.º 4
0
 /**
  * @group functional
  */
 public function testNestedAggregation()
 {
     $agg = new Nested('resellers', 'resellers');
     $min = new Min('min_price');
     $min->setField('resellers.price');
     $agg->addAggregation($min);
     $query = new Query();
     $query->addAggregation($agg);
     $results = $this->_getIndexForTest()->search($query)->getAggregation('resellers');
     $this->assertEquals(4.98, $results['min_price']['value']);
 }