您好我有问题..
我有我的Elastica存储库
namespace XX\xxx;
use FOS\ElasticaBundle\Repository;
class TestRepository extends Repository
{
public function getExamples($argOne, $argTwo) {
$query = new BoolQuery();
$matchOne = new Match();
$matchOne->setField('column_one', $argOne);
$query->addMust($matchOne);
$matchTwo = new Match();
$matchOne->setField('column_two', $argTwo);
$query->addMust($matchTwo);
return $this->find($query);
}
}
和映射
...
types:
example:
mappings:
column_one:
type: integer
column_two:
type: string
column_three:
type: date
我的问题是
我需要按第三列进行查询分组。而且我不知道该怎么做。
我将不胜感激。
最佳答案
您需要使用Aggregations
。
例:
use Elastica\Aggregation\Terms;
use Elastica\Query;
// set up the aggregation
$termsAgg = new Terms("dates");
$termsAgg->setField("column_three");
$termsAgg->setSize(10);
// add the aggregation to a Query object
$query = new Query();
$query->addAggregation($termsAgg);
$index = $elasticaClient->getIndex('someindex');
$buckets = $index->search($query)->getAggregation("dates");
foreach($buckets as $bucket){
$statsAggResult = $bucket["column_three"];
// do something with the result of the stats agg
}
在这里阅读更多:http://elastica.io/example/aggregations/terms.html