Hello I have a problem..
I have my elastica repository
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);
}
}
And mapping
...
types:
example:
mappings:
column_one:
type: integer
column_two:
type: string
column_three:
type: date
My problem is..
I need to get query group by column three. And I have no idea how to do this.
I'll be grateful for the informations..
You need to use Aggregations
.
Example:
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
}
Read more here: http://elastica.io/example/aggregations/terms.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With