0

I have an index with this kind of document:

        {
            "_id": "6827", 
            "_index": "test", 
            "_score": 1.0,
            "_source": {
                "class": [
                    {
                        "name": "physics",
                        "grade" : [
                                12,
                                2
                            ],
                    },
                    {
                        "name": "french",
                        "grade" : [
                            4,
                            8,
                        ],
                    },
                    {
                        "name": "sport",
                        "grade": [
                            14,
                            18,
                            16
                        ]
                    }
                ]
            }, 
            "_type": "student"
        }

A student may have different number of subscribed class

I would like to:

  1. know how is distributed the number of class (number of student with 1 class, with 2 classes and so on)
  2. how many times each class is taken (I know all the possible classes)

I've seen that metric aggregations are possible, and that what I want to do is possible. But I am a newbie with es and I did not succeed to make things up with this.

May anyone help ?

Community
  • 1
  • 1
Gaut
  • 1,255
  • 2
  • 15
  • 33

1 Answers1

0

I would suggest indexing the data differently. Have 1 document that represents the student taking a single class. Something like:

{
  studentID: 123,
  studentName: "foo bar",
  classID: 111,
  classType: "physics"
}

This will allow you to much more easily do the aggregations you're looking to do.

jhilden
  • 12,207
  • 5
  • 53
  • 76
  • I have just edited my question, the mapping was not the good one. Anyways, I cannot do that, this is not my elasticsearch instance... – Gaut Oct 30 '16 at 22:12