# Strange result of search children by parent

**URL:** <https://discuss.elastic.co/t/strange-result-of-search-children-by-parent/7776>\
**Category:** Elasticsearch\
**Created:** [May 19, 2012, 9:34pm UTC](https://discuss.elastic.co/t/strange-result-of-search-children-by-parent/7776 "2012-05-19T21:34:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxkazar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maxkazar/32/2880_2.png) [@maxkazar](https://discuss.elastic.co/u/maxkazar)\
**Post date:** [May 19, 2012, 9:34pm UTC](https://discuss.elastic.co/t/strange-result-of-search-children-by-parent/7776/1 "2012-05-19T21:34:17Z")

</div>

I need find all children by parent id. In my case i have notifications and  
each notification has documents.

I try to search all documents for some notifications like this

{  
"fields": [  
"highlight",  
"\_parent"  
],  
"query": {  
"bool": {  
"must": [  
{  
"terms": {  
"\_parent": [  
"4fadd2c31f48d548f5000001",  
"4faf79c61f48d548f1000006",  
"4fae27eb1f48d55f68000006",  
"4fadf6f61f48d54820000002",  
"4fae39911f48d57e3f000002",  
"4fae42681f48d52b6f000001",  
"4faf79c61f48d548f1000005",  
"4fadf0c41f48d534eb000024",  
"4fae11381f48d5586400000a",  
"4fae07611f48d55cae000014"  
],  
"minimum\_match": 1  
}  
}  
],  
"should": [  
{  
"query\_string": {  
"fields": [  
"content"  
],  
"query": "test"  
}  
}  
]  
}  
},  
"highlight": {  
"fields": {  
"content": {  
"fragment\_size": 100,  
"number\_of\_fragments": 1,  
"order": "score"  
}  
}  
}  
}

and every time result is different. One time result contain 3 items and  
second 5 items. ElasticSearch has to nodes with 10 shards (version 1.9.3)

I simplified search query:  
{  
"fields": [  
"name"  
],  
"query": {  
"term": {  
"\_parent": "4fae3e3d1f48d5261c000033"  
}  
}  
}

result the same, return one document or nothing

---

<div class="post-metadata">

**Author:** ![maxkazar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maxkazar/32/2880_2.png) [@maxkazar](https://discuss.elastic.co/u/maxkazar)\
**Post date:** [May 19, 2012, 9:34pm UTC](https://discuss.elastic.co/t/strange-result-of-search-children-by-parent/7776/2 "2012-05-19T21:34:43Z")

</div>

> I think i found a solution of my problem. Now i send query with preference  
> \_only\_node:xyz where xyz is id master node. When i set \_primary or  
> \_primary\_first result is empty. Why is it necessary to specify node id in  
> preference for right result?

---

<div class="post-metadata">

**Author:** ![maxkazar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maxkazar/32/2880_2.png) [@maxkazar](https://discuss.elastic.co/u/maxkazar)\
**Post date:** [May 20, 2012, 10:14am UTC](https://discuss.elastic.co/t/strange-result-of-search-children-by-parent/7776/3 "2012-05-20T10:14:32Z")

</div>

It's strange:

search query

{  
"fields": [  
"highlight",  
"\_parent"  
],  
"query": {  
"bool": {  
"must": [  
{  
"terms": {  
"\_parent": [  
"4fadd2c31f48d548f5000001",  
"4faf79c61f48d548f1000006",  
"4fae27eb1f48d55f68000006",  
"4fadf6f61f48d54820000002",  
"4fae39911f48d57e3f000002",  
"4fae42681f48d52b6f000001",  
"4faf79c61f48d548f1000005",  
"4fadf0c41f48d534eb000024",  
"4fae11381f48d5586400000a",  
"4fae07611f48d55cae000014"  
],  
"minimum\_match": 1  
}  
}  
],  
"should": [  
{  
"query\_string": {  
"fields": [  
"content"  
],  
"query": "test"  
}  
}  
]  
}  
},  
"highlight": {  
"fields": {  
"content": {  
"fragment\_size": 100,  
"number\_of\_fragments": 1,  
"order": "score"  
}  
}  
}  
}

1. Search without preference - 2 or 3 result items, (first 2 then 3) and  
item is unique
2. Search with preference = \_primary - each result empty  
3, Search with \_only\_node:xyz - 5 item result contains 2 and 3 result item  
from first step

Screenshot of my elasticseach head

[https://lh5.googleusercontent.com/-tIMUrVahwLc/T7jDDZ0vLZI/AAAAAAAAAJw/JmYOcr1W14Q/s1600/Screenshot+from+2012-05-20+14%3A01%3A18.png](https://lh5.googleusercontent.com/-tIMUrVahwLc/T7jDDZ0vLZI/AAAAAAAAAJw/JmYOcr1W14Q/s1600/Screenshot+from+2012-05-20+14%3A01%3A18.png)

---

<div class="post-metadata">

**Author:** ![maxkazar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maxkazar/32/2880_2.png) [@maxkazar](https://discuss.elastic.co/u/maxkazar)\
**Post date:** [May 20, 2012, 10:25am UTC](https://discuss.elastic.co/t/strange-result-of-search-children-by-parent/7776/4 "2012-05-20T10:25:21Z")

</div>

> xyz - is id of Bulldozer (master)

---

<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, 3:28am UTC](https://discuss.elastic.co/t/strange-result-of-search-children-by-parent/7776/5 "2017-07-06T03:28:05Z")

</div>


