Strange result of search children by parent


(maxkazar) #1

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


(maxkazar) #2

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?


(system) #3