# Nested Query Does Not Return Data Correctly

**URL:** <https://discuss.elastic.co/t/nested-query-does-not-return-data-correctly/133727>\
**Category:** Elasticsearch\
**Created:** [May 29, 2018, 5:10pm UTC](https://discuss.elastic.co/t/nested-query-does-not-return-data-correctly/133727 "2018-05-29T17:10:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TomTom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tomtom/32/3676_2.png) [@TomTom](https://discuss.elastic.co/u/TomTom)\
**Post date:** [May 29, 2018, 5:10pm UTC](https://discuss.elastic.co/t/nested-query-does-not-return-data-correctly/133727/1 "2018-05-29T17:10:36Z")

</div>

I'm doing a query on nested data and the results that should return do not appear in the results.

Query example:

```
{
    "query": {
        "bool": {
            "must": [
                {
                    "term": {
                        "account": 15620
                    }
                },
                {
                    "nested": {
                        "path": "replies.content",
                        "query": {
                            "bool": {
                                "must": [
                                    {
                                        "term": {
                                            "replies.content.operator": 38228
                                        }
                                    }
                                ]
                            }
                        },
                        "inner_hits": {
                            "_source": false,
                            "docvalue_fields": [
                                "replies.content.historyid"
                            ]
                        }
                    }
                }
            ]
        }
    },
    "aggs": {
        "sum_worktime": {
            "sum": {
                "field": "worktime"
            }
        }
    },
    "_source": [],
    "script_fields": {
        "deadline_ok": {
            "script": {
                "id": "deadline",
                "params": {
                    "current_timestamp": 1527611998216
                }
            }
        },
        "start_deadline_ok": {
            "script": {
                "id": "start_deadline",
                "params": {
                    "current_timestamp": 1527611998216
                }
            }
        }
    },
    "size": 10000,
    "sort": {
        "item": {
            "order": "asc"
        }
    }
}

```

I have this object inside my return JSON

```
],
                    "replies": [
                        {
                            "content": [
                                {
                                    "historyid": 6279537,
                                    "message": "Message",
                                    "timestamp": "2018-05-26T17:31:33-03",
                                    "situation": 2,
                                    "operator": 38228,
                                    "start": "2018-05-23T14:40:00-03",
                                    "end": "2018-05-23T15:30:00-03",
                                    "worktime": 3000,
                                    "temp_worktime": 0,
                                    "reopen": null,
                                    "customerid": 0,
                                    "mimetype": "text\/html"
                                }, ...

```

Note that the id **38228** operator and _ **6279537** _ historyid is inside it, but this record does not appear inside inner\_hits\> replies.content\> hits\> hits\> fields.

Am I doing something wrong on the search?

This is the inner\_hits:

```
"inner_hits": {
    "replies.content": {
        "hits": {
            "total": 4,
            "max_score": 1.0,
            "hits": [
                {
                    "_index": "tickets",
                    "_type": "ticket",
                    "_id": "3915372-15620",
                    "_nested": {
                        "field": "replies.content",
                        "offset": 5
                    },
                    "_score": 1.0,
                    "fields": {
                        "replies.content.historyid": [
                            6119051
                        ]
                    }
                },
                {
                    "_index": "tickets",
                    "_type": "ticket",
                    "_id": "3915372-15620",
                    "_nested": {
                        "field": "replies.content",
                        "offset": 2
                    },
                    "_score": 1.0,
                    "fields": {
                        "replies.content.historyid": [
                            6083419
                        ]
                    }
                },
                {
                    "_index": "tickets",
                    "_type": "ticket",
                    "_id": "3915372-15620",
                    "_nested": {
                        "field": "replies.content",
                        "offset": 1
                    },
                    "_score": 1.0,
                    "fields": {
                        "replies.content.historyid": [
                            6080493
                        ]
                    }
                }
            ]
        }
    }
}
```

---

<div class="post-metadata">

**Author:** ![TomTom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tomtom/32/3676_2.png) [@TomTom](https://discuss.elastic.co/u/TomTom)\
**Post date:** [May 29, 2018, 5:51pm UTC](https://discuss.elastic.co/t/nested-query-does-not-return-data-correctly/133727/2 "2018-05-29T17:51:14Z")

</div>

I think I found the problem:

> size  
> The maximum number of hits to return per inner\_hits. By default the top three matching hits are returned.

Where do I change this option in my query?

---

<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:** [June 26, 2018, 5:51pm UTC](https://discuss.elastic.co/t/nested-query-does-not-return-data-correctly/133727/3 "2018-06-26T17:51:20Z")

</div>

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