# Distribution tables from survey data

**URL:** <https://discuss.elastic.co/t/distribution-tables-from-survey-data/46405>\
**Category:** Elasticsearch\
**Created:** [April 5, 2016, 2:14pm UTC](https://discuss.elastic.co/t/distribution-tables-from-survey-data/46405 "2016-04-05T14:14:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tier](https://avatars.discourse-cdn.com/v4/letter/t/258eb7/32.png) [@tier](https://discuss.elastic.co/u/tier)\
**Post date:** [April 5, 2016, 2:14pm UTC](https://discuss.elastic.co/t/distribution-tables-from-survey-data/46405/1 "2016-04-05T14:14:40Z")

</div>

Hi,

I am storing survey data like this:

```json
[  
  {  
    "userid":1,
    "answers":[  
      {  
        "key":"gender",
        "value":"male"
      },
      {  
        "key":"color",
        "value":"red"
      },
      {  
        "key":"vehicle",
        "value":"car"
      }
    ]
  },
  {  
    "userid":2,
    "answers":[  
      {  
        "key":"gender",
        "value":"female"
      },
      {  
        "key":"color",
        "value":"blue"
      },
      {  
        "key":"vehicle",
        "value":"bike"
      }
    ]
  },
  ......
]

```

That means lots of users with lots of answers to different questions. I have to be flexible about what questions have been asked, so I chose the key/value style.

Now I want to find a query that will give me a distribution table on gender and color.  
That means: A 2-dimensional table having gender as one axis and color as one axis showing me all possible terms in those fields.  
I want to have a nice overview on how many women like the color red or how many men like blue and so on.

I tried a lot with nested filtered terms aggregations and did not succeed yet.

Any hints would be appreciated...

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 11:02pm UTC](https://discuss.elastic.co/t/distribution-tables-from-survey-data/46405/2 "2017-07-05T23:02:15Z")

</div>

Closed on July 5, 2017, 11:02pm UTC


