Elasticsearch foselastica 存储库和 groupBy

Jac*_*Red 5 symfony elasticsearch elastica foselasticabundle

你好我有一个问题..

我有我的 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);
  }
}
Run Code Online (Sandbox Code Playgroud)

和测绘

...
types:
   example:
      mappings:
         column_one:
              type: integer
         column_two:
              type: string
         column_three:
              type: date
Run Code Online (Sandbox Code Playgroud)

我的问题是..

我需要按第三列获取查询组。我不知道该怎么做。

我将不胜感激的信息..

Paw*_*zuk 5

你需要使用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
}
Run Code Online (Sandbox Code Playgroud)

在这里阅读更多信息: http: //elastica.io/example/aggregations/terms.html