# Parent/child queries

**URL:** <https://discuss.elastic.co/t/parent-child-queries/25046>\
**Category:** Elasticsearch\
**Created:** [July 7, 2015, 2:13pm UTC](https://discuss.elastic.co/t/parent-child-queries/25046 "2015-07-07T14:13:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![j0hnsmith](https://avatars.discourse-cdn.com/v4/letter/j/4af34b/32.png) [@j0hnsmith](https://discuss.elastic.co/u/j0hnsmith)\
**Post date:** [July 7, 2015, 2:13pm UTC](https://discuss.elastic.co/t/parent-child-queries/25046/1 "2015-07-07T14:13:02Z")

</div>

Let's say I have a parent/child relationship, Blog posts (parent) and comments (child), posts contain the post text and comments contain comment text.

I want to offer search functionality that will return comments, but will consider and score based on the content of **both** the comment text and the parent post text eg with these documents (shown as nested to save space)

```
post:
  text: foo
  comments: [
    { date: today, text: "Great post" }
  ]

post:
  text: bar
  comments: [
    { date: today, text: "Great post, as was the earlier one about foo" }
  ]

```

If the term we're looking for is 'foo' both comments will be in the results.

I've seen has\_child/has\_parent queries and filters but they appear only to consider the fields of **either** the parent or the child, I want to consider both.

What kind of query can I use to achieve this without resorting to a nested relationship?

---

<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, 12:03am UTC](https://discuss.elastic.co/t/parent-child-queries/25046/2 "2017-07-06T00:03:11Z")

</div>


