Elasticsearch group data

Hello, if I have data like this

ID Username Role Email
1001 johndoe admin johndoe@mail.com
1001 jonathan.doe user johndoe@mail.com
1001 johnnydoe user johndoe@mail.com

Can I do some kind of grouping?
Notice that :

  • ID is same for all rows
  • there are 3 distinct usernames
  • there are 2 distinct roles
  • email is same for all rows
  • Other ID might have different combination (e.g 4 distinct emails but all other data are the same)

Can I do query on elasticsearch, so I get data like this :

{
   "id":"1001",
   "username":[
      "johndoe",
      "jonathan.doe",
      "johnnydoe"
   ],
   "role":[
      "admin",
      "user"
   ],
   "email":[
      "johndoe@mail.com"
   ]
}

Thank you

I'd run a terms agg on id with 3 inner terms aggs on username, role, email.

Hi, can you give example?

This one won't work

{
    "from": 0,
    "size": 100,
    "query": {
        "bool": {
            "should": [
                {
                    "match": {
                        "id": {
                            "query": "1001",
                            "fuzziness": "0"
                        }
                    }
                }
            ]
        }
    },
    "aggs": {
        "usernames": {
            "terms": {
                "field": "username"
            }
        }
    }
}

What does it mean?

Could you provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.