# Multiple has\_child queries

**URL:** <https://discuss.elastic.co/t/multiple-has-child-queries/13995>\
**Category:** Elasticsearch\
**Created:** [October 17, 2013, 3:51pm UTC](https://discuss.elastic.co/t/multiple-has-child-queries/13995 "2013-10-17T15:51:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcelo\_Elias\_Del\_Va](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marcelo_elias_del_va/32/1957_2.png) [@Marcelo\_Elias\_Del\_Va](https://discuss.elastic.co/u/Marcelo_Elias_Del_Va)\
**Post date:** [October 17, 2013, 3:51pm UTC](https://discuss.elastic.co/t/multiple-has-child-queries/13995/1 "2013-10-17T15:51:40Z")

</div>

Hello,

```
I would like to run multiple has_child queries and find a set of 

```

documents that matches them based on boolean conditions. Something like:  
give me all documents where (there is a child A which matches field1 =  
value1) or ( (there is a child B that matches range field 2 between A and B  
) AND (there is a child C that matches field 3 = value 3) )

```
Besides that, I want to calculate a score for each of the has_child 

```

queries and match only those with score between S1 and S2.  
I created a query that does exactly what I want to filter for just 1  
child:

documents/document/\_search  
{  
"query": {  
"function\_score": {  
"query": {  
"has\_child" : {  
"type" : "comment",  
"score\_type" : "sum",  
"boost": 1,  
"query" : {  
"range": {  
"date": {  
"lte": 20130204,  
"gte": 20130201,  
"boost": 1  
}  
}  
}  
}  
},  
"boost": "1",  
"script\_score" : {  
"script" : "\_score"  
},  
"boost\_mode":"replace"  
}

```
}

```

}

```
But when I have multiple child queries and with boolean conditions 

```

between them, it became harder. Bellow is what I was trying to do, but it  
seems it won't work because I cannot have scores on filters... Any thought  
about how to solve this?

{  
"query": {  
"filtered" : {  
"query": {  
"has\_child" : {  
"type" : "comment",  
"score\_type" : "sum",  
"boost": 1,  
"query" : {  
"range": {  
"date": {  
"lte": 20130204,  
"gte": 20130201,  
"boost": 1  
}  
}  
}  
}  
},  
"filter" : {  
"or" : [  
{  
"has\_child" : {  
"type" : "comment",  
"query" : {  
"range": {  
"date": {  
"lte": 20130204,  
"gte": 20130201  
}  
}  
}  
}  
}  
]  
}  
}  
}  
}

Best regards,  
Marcelo.

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:11am UTC](https://discuss.elastic.co/t/multiple-has-child-queries/13995/2 "2017-07-06T02:11:53Z")

</div>


