# Groupby on dynamic fields

**URL:** <https://discuss.elastic.co/t/groupby-on-dynamic-fields/104056>\
**Category:** Elasticsearch\
**Created:** [October 16, 2017, 7:45am UTC](https://discuss.elastic.co/t/groupby-on-dynamic-fields/104056 "2017-10-16T07:45:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yogesh\_BG](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yogesh_bg/32/70018_2.png) [@Yogesh\_BG](https://discuss.elastic.co/u/Yogesh_BG)\
**Post date:** [October 16, 2017, 7:45am UTC](https://discuss.elastic.co/t/groupby-on-dynamic-fields/104056/1 "2017-10-16T07:45:30Z")

</div>

Hi

I have doc like below

## doc1:

```
"url":{
"http://hello.com":10,
"http://hello2.com":20,
}

```

## doc2:

```
"url":{
"http://hello3.com":10,
"http://hello2.com":20,
"http://hello4.com":10,
"http://hello6.com":20
}

```

I want to group by fields under url[in my case url is a nested field]

The result should be combined as below...

which actually matches the url and sum the count

## doc1:

```
"url":{
"http://hello.com":10,
"http://hello2.com":40,
"http://hello3.com":10,
"http://hello4.com":10,
"http://hello6.com":20
}

```

Basically i dont know what are the fields present inside the url's...

Is there a way to get aggregation like this?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 16, 2017, 8:09am UTC](https://discuss.elastic.co/t/groupby-on-dynamic-fields/104056/2 "2017-10-16T08:09:38Z")

</div>

You are going to produce a lot of fields in the mapping and may be hit soon the default 1000 fields in mapping.

May be a key/value approach would be better?

It will then make that easier to build an aggregation on.

---

<div class="post-metadata">

**Author:** ![Yogesh\_BG](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yogesh_bg/32/70018_2.png) [@Yogesh\_BG](https://discuss.elastic.co/u/Yogesh_BG)\
**Post date:** [October 16, 2017, 8:52am UTC](https://discuss.elastic.co/t/groupby-on-dynamic-fields/104056/3 "2017-10-16T08:52:10Z")

</div>

can you give me an example?

I had kept url as key and count as value...

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 16, 2017, 10:26am UTC](https://discuss.elastic.co/t/groupby-on-dynamic-fields/104056/4 "2017-10-16T10:26:03Z")

</div>

Did you change the document form? Or still using initial structure?

If the later, I don’t know how you can do it. May be with this? [https://www.elastic.co/guide/en/elasticsearch/reference/5.6/mapping-field-names-field.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/mapping-field-names-field.html)

---

<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:** [November 13, 2017, 10:26am UTC](https://discuss.elastic.co/t/groupby-on-dynamic-fields/104056/5 "2017-11-13T10:26:46Z")

</div>

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