How to query and return whether a result has at least one child?

Hello, I have a type (document) which has a child type (document_partials). Not all documents have a document_partial, but some do.

I want a query that lets me search against my document type and returns if it has a child (document_partial) or not. I want to return all results that match my search query, but I also want to get back whether the result has a child or not.

I am running into the issue of not being able to search for items that do and don't have children when using has_child. Similar to needing to min_children to 0 like in this issue: https://github.com/elastic/elasticsearch/issues/21224.

You can either wrap has_child into function score and check the score (if you are not using score in your search) or you can add it as a should clause and name it.

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