# About parent-child datatypes

**URL:** https://discuss.elastic.co/t/about-parent-child-datatypes/220375
**Category:** Elasticsearch
**Created:** [February 21, 2020, 1:35pm UTC](https://discuss.elastic.co/t/about-parent-child-datatypes/220375 "2020-02-21T13:35:12Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![critskiy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/critskiy/32/48115_2.png) [@critskiy](https://discuss.elastic.co/u/critskiy)
#### Post date: [February 21, 2020, 1:35pm UTC](https://discuss.elastic.co/t/about-parent-child-datatypes/220375/1 "2020-02-21T13:35:12Z")

</div>

Hello there! I was experimenting around parent-child relationships and I found interesting thing, but, I'd be glad if anyone would point out what needs to be done correctly.

> Let's suppose we have an index with parent-child relationship, and we want to find parent with \> different childs and different values though.

I try to build something like:

```auto
	"query": {
		"bool": {
			"must": [
				{
					"match": {"type": "url"}
				},
				{
					"match": {"isMain": false}
				},
				{
					"has_child": {
						"type": "child1",
						"query": {
							"bool": {
								"must": 
									{"match": { "cube.x": 0 }}
								
							}
						}
					}
				},
				{
					"has_child": {
						"type": "child1",
						"query": {
							"bool": {
								"must": {
									"match": {"cube.type": "FKU"}
								}
							}
						}
					}
				}
			]
		}
	}
}
```

---

<div class="post-metadata">

### Author: ![critskiy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/critskiy/32/48115_2.png) [@critskiy](https://discuss.elastic.co/u/critskiy)
#### Post date: [February 21, 2020, 1:39pm UTC](https://discuss.elastic.co/t/about-parent-child-datatypes/220375/2 "2020-02-21T13:39:13Z")

</div>

But the result give me the same hits value as it was when I was trying to search criterias on one level. But when I did the query below, the result was **correct**. So, maybe I am mistaken, but was there done any improvement to such search queries?  
Query:

```auto
	"query": {
		"bool": {
			"must": [
				{
					"match": {"type": "url"}
				},
				{
					"match": {"isMain": false}
				},
				{
					"has_child": {
						"type": "child1",
						"query": {
							"bool": {
								"must": {
									"match": { "cube.x": 0 }
								},
								"must_not": {
									"match": { "cube.type": "FKU" }
								}
							}
						}
					}
				},
				{
					"has_child": {
						"type": "child1",
						"query": {
							"bool": {
								"must_not": {
									"match": { "cube.x": 0 }
								},
								"must": {
									"match": { "cube.type": "FKU" }
								}
							}
						}
					}
				}
			]
		}
	}
}
```

---

<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: [March 20, 2020, 1:43pm UTC](https://discuss.elastic.co/t/about-parent-child-datatypes/220375/3 "2020-03-20T13:43:48Z")

</div>

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