# Parent/Child combination Script possible?

**URL:** <https://discuss.elastic.co/t/parent-child-combination-script-possible/16962>\
**Category:** Elasticsearch\
**Created:** [April 11, 2014, 3:53pm UTC](https://discuss.elastic.co/t/parent-child-combination-script-possible/16962 "2014-04-11T15:53:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas\_Bolis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomas_bolis/32/700_2.png) [@Thomas\_Bolis](https://discuss.elastic.co/u/Thomas_Bolis)\
**Post date:** [April 11, 2014, 3:53pm UTC](https://discuss.elastic.co/t/parent-child-combination-script-possible/16962/1 "2014-04-11T15:53:08Z")

</div>

Hello,

I have two document types which are utilizing a parent/child relation. I  
want to perform an aggregation where the script utilizes fields from both  
documents. Is that possible?

More specifically:

Parent Document

{

> "tag:{  
> "\_id": {  
> "path": "tag\_id"  
> },  
> "properties": {  
> "tag\_id": {"index": "not\_analyzed","type": "string"},  
> "name": {"index": "not\_analyzed","type": "string"}  
> "tag\_counter": {"type": "integer"}  
> }  
> }  
> }

Child Document

{

> "click:{  
> "\_parent": {  
> "type": "tag"  
> },  
> "properties": {  
> "type": {"index": "not\_analyzed","type": "string"},  
> "clicks\_counter": {"type": "integer"}  
> }  
> }  
> }

curl -XGET "[http://localhost:9200/tags-index/tags,clicks/\_search](http://localhost:9200/tags-index/tags,clicks/_search)" -d'

> {  
> "aggregations": {  
> "one\_day\_filter": {  
> "filter": {  
> "range": {  
> "ts": {  
> "gte": "2014-03-15T00:00:00",  
> "lt": "2014-03-15T01:00:00"  
> }  
> }  
> },  
> "aggregations": {  
> "parent": {  
> "filter": {  
> "has\_child": {  
> "type": "clicks",  
> "query": {  
> "match\_all": {}  
> }  
> }  
> },  
> "aggregations": {  
> "metrics": {  
> "terms": {  
> "script": "_doc["tags.tag\_counter"].value -  
> "doc["clicks.clicks\_counter"].value_"  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> },  
> "size": 0  
> }'

Thanks  
Thomas

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/3ffee913-9e82-4862-befe-e0f7ff9038e8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3ffee913-9e82-4862-befe-e0f7ff9038e8%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Sven\_Beauprez](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@Sven\_Beauprez](https://discuss.elastic.co/u/Sven_Beauprez)\
**Post date:** [April 12, 2014, 11:43am UTC](https://discuss.elastic.co/t/parent-child-combination-script-possible/16962/2 "2014-04-12T11:43:29Z")

</div>

I am interested in this also, because this could solve my problem also:  
[https://groups.google.com/d/topic/elasticsearch/BmxECoKM\_\_I/discussion](https://groups.google.com/d/topic/elasticsearch/BmxECoKM__I/discussion)

regards,

Sven

On Friday, April 11, 2014 5:53:08 PM UTC+2, Thomas wrote:

> Hello,
> 
> I have two document types which are utilizing a parent/child relation. I  
> want to perform an aggregation where the script utilizes fields from both  
> documents. Is that possible?
> 
> More specifically:
> 
> Parent Document
> 
> {
> 
> > "tag:{  
> > "\_id": {  
> > "path": "tag\_id"  
> > },  
> > "properties": {  
> > "tag\_id": {"index": "not\_analyzed","type": "string"},  
> > "name": {"index": "not\_analyzed","type": "string"}  
> > "tag\_counter": {"type": "integer"}  
> > }  
> > }  
> > }
> 
> Child Document
> 
> {
> 
> > "click:{  
> > "\_parent": {  
> > "type": "tag"  
> > },  
> > "properties": {  
> > "type": {"index": "not\_analyzed","type": "string"},  
> > "clicks\_counter": {"type": "integer"}  
> > }  
> > }  
> > }
> 
> curl -XGET "[http://localhost:9200/tags-index/tags,clicks/\_search](http://localhost:9200/tags-index/tags,clicks/_search)" -d'
> 
> > {  
> > "aggregations": {  
> > "one\_day\_filter": {  
> > "filter": {  
> > "range": {  
> > "ts": {  
> > "gte": "2014-03-15T00:00:00",  
> > "lt": "2014-03-15T01:00:00"  
> > }  
> > }  
> > },  
> > "aggregations": {  
> > "parent": {  
> > "filter": {  
> > "has\_child": {  
> > "type": "clicks",  
> > "query": {  
> > "match\_all": {}  
> > }  
> > }  
> > },  
> > "aggregations": {  
> > "metrics": {  
> > "terms": {  
> > "script": "_doc["tags.tag\_counter"].value -  
> > "doc["clicks.clicks\_counter"].value_"  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }  
> > },  
> > "size": 0  
> > }'
> 
> Thanks  
> Thomas

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/2ca1df0f-475e-467e-acb1-32a617b7c8ee%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2ca1df0f-475e-467e-acb1-32a617b7c8ee%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Thomas\_Bolis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomas_bolis/32/700_2.png) [@Thomas\_Bolis](https://discuss.elastic.co/u/Thomas_Bolis)\
**Post date:** [April 14, 2014, 6:38am UTC](https://discuss.elastic.co/t/parent-child-combination-script-possible/16962/3 "2014-04-14T06:38:59Z")

</div>

Thanks Sven,

Yes this would solve a lot of use cases..

Is there anyone that can respond whether we should create an issue for  
that? The link provided does not mention whether finally this should be  
opened as an issue

Thanks  
Thomas

On Friday, 11 April 2014 18:53:08 UTC+3, Thomas wrote:

> Hello,
> 
> I have two document types which are utilizing a parent/child relation. I  
> want to perform an aggregation where the script utilizes fields from both  
> documents. Is that possible?
> 
> More specifically:
> 
> Parent Document
> 
> {
> 
> > "tag:{  
> > "\_id": {  
> > "path": "tag\_id"  
> > },  
> > "properties": {  
> > "tag\_id": {"index": "not\_analyzed","type": "string"},  
> > "name": {"index": "not\_analyzed","type": "string"}  
> > "tag\_counter": {"type": "integer"}  
> > }  
> > }  
> > }
> 
> Child Document
> 
> {
> 
> > "click:{  
> > "\_parent": {  
> > "type": "tag"  
> > },  
> > "properties": {  
> > "type": {"index": "not\_analyzed","type": "string"},  
> > "clicks\_counter": {"type": "integer"}  
> > }  
> > }  
> > }
> 
> curl -XGET "[http://localhost:9200/tags-index/tags,clicks/\_search](http://localhost:9200/tags-index/tags,clicks/_search)" -d'
> 
> > {  
> > "aggregations": {  
> > "one\_day\_filter": {  
> > "filter": {  
> > "range": {  
> > "ts": {  
> > "gte": "2014-03-15T00:00:00",  
> > "lt": "2014-03-15T01:00:00"  
> > }  
> > }  
> > },  
> > "aggregations": {  
> > "parent": {  
> > "filter": {  
> > "has\_child": {  
> > "type": "clicks",  
> > "query": {  
> > "match\_all": {}  
> > }  
> > }  
> > },  
> > "aggregations": {  
> > "metrics": {  
> > "terms": {  
> > "script": "_doc["tags.tag\_counter"].value -  
> > "doc["clicks.clicks\_counter"].value_"  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }  
> > },  
> > "size": 0  
> > }'
> 
> Thanks  
> Thomas

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/9a188e78-e220-4afd-b840-e85ea0cade4e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9a188e78-e220-4afd-b840-e85ea0cade4e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 1:36am UTC](https://discuss.elastic.co/t/parent-child-combination-script-possible/16962/4 "2017-07-06T01:36:05Z")

</div>


