# Scripted\_fields for child records in elasticsearch

**URL:** <https://discuss.elastic.co/t/scripted-fields-for-child-records-in-elasticsearch/291761>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-searchable-snapshots\
**Created:** [December 14, 2021, 8:25am UTC](https://discuss.elastic.co/t/scripted-fields-for-child-records-in-elasticsearch/291761 "2021-12-14T08:25:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BIRENDRA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/birendra/32/64625_2.png) [@BIRENDRA](https://discuss.elastic.co/u/BIRENDRA)\
**Post date:** [December 14, 2021, 8:25am UTC](https://discuss.elastic.co/t/scripted-fields-for-child-records-in-elasticsearch/291761/1 "2021-12-14T08:25:10Z")

</div>

Hi Team,

I have a requirement where I have to put a flag as True or False if my parent record has child records exists in the elastic index. For this purpose I am making use of scripted field but I guess I cannot use it within should clause.

Below is my query that I have created. I am not sure where I am going wrong.

POST players/\_search  
{  
"query": {  
"bool": {  
"should": [  
{  
"has\_child": {  
"type": "club",  
"query": {  
"bool": {  
"must": [  
{  
"match\_all": {}  
}  
]  
}  
}  
},  
"script\_fields": {  
"inClub": {  
"script": "true"  
}  
}  
}  
]  
}  
}  
}  
}  
}

I got the below response.

{  
"error": {  
"root\_cause": [  
{  
"type": "parsing\_exception",  
"reason": "[has\_child] malformed query, expected [END\_OBJECT] but found [FIELD\_NAME]",  
"line": 18,  
"col": 11  
}  
],  
"type": "parsing\_exception",  
"reason": "[has\_child] malformed query, expected [END\_OBJECT] but found [FIELD\_NAME]",  
"line": 18,  
"col": 11  
},  
"status": 400  
}

Any light on this will be helpful.

Thanks,

---

<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:** [January 11, 2022, 8:25am UTC](https://discuss.elastic.co/t/scripted-fields-for-child-records-in-elasticsearch/291761/2 "2022-01-11T08:25:59Z")

</div>

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