How to count the entries having the same array element value of a property?

Each entry in my elasticsearch server has this form :

    "_index": "nuxeo_doc",
    "_type": "doc",
    "_id": "ce8ac97d-0376-49b1-b665-cac98081b5d5",
    "_version": 1,
    "found": true,
    "_source": {
        "titre": "Nuxeo GDPR Brochure.pdf",
        "rating": 0,
        "repository": "default",
        "uuid": "ce8ac97d-0376-49b1-b665-cac98081b5d5",
        "nbr_comment": "0",
        "file": {
            "mime-type": "application/pdf",
            "name": "Nuxeo GDPR Brochure.pdf",
            "digest": "7c874ecf777bcad8bc64f1590522e07e",
            "length": 371567,
            "encoding": ""
        "date_modify": "2020-07-30T11:47:01.922Z",
        "tag": ['tag_1', 'tag_2'],
        "url": "/default-domain/workspaces/Nuxeo Marketing Content/Reports/Nuxeo GDPR Brochure.pdf",
        "auteur": "Administrator",
        "date_create": "2018-02-21T21:10:20.407Z"

I want to count the number of entries that have the same array value from the property tag ; for example tag_1. If I do it on a non-array property then it is easy :

$index = $this->client->getIndex($this->container->getParameter('nuxeo_doc_index'));
$queryPart = new QueryBoolQuery();
$query = Query::create($queryPart);
$termAgg = (new AggregationSum('name'))->setField('nb');
$found = $index->search($query);
return $found->getTotalHits();

So how to achieve this particular goal ?

Source: Symfony4 Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *