# Queries custom\_score, has\_parent, has\_child used with only filters

**URL:** <https://discuss.elastic.co/t/queries-custom-score-has-parent-has-child-used-with-only-filters/12380>\
**Category:** Elasticsearch\
**Created:** [June 12, 2013, 1:31pm UTC](https://discuss.elastic.co/t/queries-custom-score-has-parent-has-child-used-with-only-filters/12380 "2013-06-12T13:31:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![q42jaap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/q42jaap/32/2241_2.png) [@q42jaap](https://discuss.elastic.co/u/q42jaap)\
**Post date:** [June 12, 2013, 1:31pm UTC](https://discuss.elastic.co/t/queries-custom-score-has-parent-has-child-used-with-only-filters/12380/1 "2013-06-12T13:31:52Z")

</div>

I created an issue about not being able to specify filters on a lot of  
levels in the query DSL:

> <https://github.com/elastic/elasticsearch/issues/3165>

So for instance this has\_parent filter:  
{  
"has\_parent": {  
"type": "accos",  
"query": {  
"filtered": {  
"filter": {  
"term": {  
"locationCode": "0512"  
}  
}  
}  
}  
}  
}

This is very verbose and could (in theory) be specified like this:  
{  
"has\_parent": {  
"type": "accos",  
"filter": {  
"term": {  
"locationCode": "0512"  
}  
}  
}  
}

Being a filter itself, the has\_parent filter now takes a query, which seems  
strange.

For query's has\_child, has\_parent and custom\_score, I also see myself doing  
this. For example:

{  
"query": {  
"filtered": {  
"query": {  
"has\_child": {  
"type": "prices",  
"score\_type": "max",  
"query": {  
"custom\_score": {  
"script": "-doc['pricePerPerson'].value",  
"query": {  
"filtered": {  
"filter": {  
"term": {  
"careType": "LO"  
}  
}  
}  
}  
}  
}  
}  
},  
"filter": {  
"term": {  
"locationCode": "0512"  
}  
}  
}  
}  
}

The custom score query doesn't use \_score in the script field, and to be  
able to use caching I want a filter, so I have to use a filtered query.  
This could have been written (again, in theory) like this:

{  
"query": {  
"filtered": {  
"query": {  
"has\_child": {  
"type": "prices",  
"score\_type": "max",  
"query": {  
"custom\_score": {  
"script": "-doc['pricePerPerson'].value",  
"filter": {  
"term": {  
"careType": "LO"  
}  
}  
}  
}  
}  
},  
"filter": {  
"term": {  
"locationCode": "0512"  
}  
}  
}  
}  
}

In fact, I think this could be applied to lots of query types that only  
take a query parameter now.

Are there any (possibly technical) things I'm missing?

Jaap

--  
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:31am UTC](https://discuss.elastic.co/t/queries-custom-score-has-parent-has-child-used-with-only-filters/12380/2 "2017-07-06T02:31:35Z")

</div>


