# Nested Inner Hits not showing inside a function, why?

**URL:** <https://discuss.elastic.co/t/nested-inner-hits-not-showing-inside-a-function-why/104102>\
**Category:** Elasticsearch\
**Created:** [October 16, 2017, 2:37pm UTC](https://discuss.elastic.co/t/nested-inner-hits-not-showing-inside-a-function-why/104102 "2017-10-16T14:37:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kenneth\_Canet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kenneth_canet/32/23081_2.png) [@kenneth\_Canet](https://discuss.elastic.co/u/kenneth_Canet)\
**Post date:** [October 16, 2017, 2:37pm UTC](https://discuss.elastic.co/t/nested-inner-hits-not-showing-inside-a-function-why/104102/1 "2017-10-16T14:37:51Z")

</div>

Hello Everyone,

I'm working on upgrading the query from ES 2.X to 5.6. But i'm having problem with inner hits inside the function, see my query below.

Mappings:

```
PUT test
{
  "mappings": {
    "doc": {
      "properties": {
        "comments": {
          "type": "nested",
          "properties": {
            "text": {
              "type": "text",
              "store": true
            }
          }
        }
      }
    }
  }
}
```

Data:

```
PUT test/doc/1?refresh
{
  "title": "Test title",
  "comments": [
    {
      "author": "kimchy",
      "text": "comment text"
    },
    {
      "author": "nik9000",
      "text": "words words words"
    }
  ]
}
```

Query/DSL:

```
POST test/_search
{
  "query": {
    "function_score": {
      "query": {
        "function_score": {
          "query": {
            "bool": {
              "should":[
                {
                  "query_string": {
                    "boost": 1.0,
                    "query": "Test",
                    "default_operator": "and",
                    "fields": [
                      "title"
                    ]
                  }
                }
              ],
              "filter": {
                "terms": {
                  "_id": [
                    "1"
                  ]
                }
              }
            }
          },
          "functions": [
            {
              "filter": {
                "bool": {
                  "must":[
                    {
                      "nested":{
                        "path": "comments",
                        "score_mode": "max",
                        "query":{
                          "bool": {
                            "must":[
                              {
                                "query_string": {
                                  "query": "Kim",
                                  "default_field": "comments.author",
                                  "default_operator": "and"
                                }
                              }
                            ]
                          }
                        },
                        "inner_hits": {
                          "name": "sdInnerHits1",
                          "size": 100
                        }
                      }
                    }
                  ]
                }
              },
              "weight": 1.0
            }
          ],
          "score_mode": "max",
          "boost_mode": "sum"
        }
      },
      "functions": [
        
      ],
      "score_mode": "sum",
      "boost_mode": "sum"
    }
  }
}
```

Basically, what i'm trying to accomplish here is to get the inner hits named "sdInnerhits1".

Thank you!

-Kenneth

---

<div class="post-metadata">

**Author:** ![kenneth\_Canet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kenneth_canet/32/23081_2.png) [@kenneth\_Canet](https://discuss.elastic.co/u/kenneth_Canet)\
**Post date:** [October 16, 2017, 3:17pm UTC](https://discuss.elastic.co/t/nested-inner-hits-not-showing-inside-a-function-why/104102/2 "2017-10-16T15:17:20Z")

</div>

Updated Query/DSL:

```
POST test/_search
{
  "query": {
    "function_score": {
      "query": {
        "function_score": {
          "query": {
            "bool": {
              "should":[
                {
                  "query_string": {
                    "boost": 1.0,
                    "query": "Test",
                    "default_operator": "and",
                    "fields": [
                      "title"
                    ]
                  }
                }
              ],
              "filter": {
                "terms": {
                  "_id": [
                    "1"
                  ]
                }
              }
            }
          },
          "functions": [
            {
              "filter": {
                "bool": {
                  "must":[
                    {
                      "nested":{
                        "path": "comments",
                        "score_mode": "max",
                        "query":{
                          "bool": {
                            "must":[
                              {
                                "query_string": {
                                  "query": "kimchy",
                                  "default_field": "comments.author",
                                  "default_operator": "and"
                                }
                              }
                            ]
                          }
                        },
                        "inner_hits": {
                          "name": "sdInnerHits1",
                          "size": 100
                        }
                      }
                    }
                  ]
                }
              },
              "weight": 0.0
            }
          ],
          "score_mode": "max",
          "boost_mode": "sum"
        }
      },
      "functions": [
        
      ],
      "score_mode": "sum",
      "boost_mode": "sum"
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![kenneth\_Canet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kenneth_canet/32/23081_2.png) [@kenneth\_Canet](https://discuss.elastic.co/u/kenneth_Canet)\
**Post date:** [October 16, 2017, 3:25pm UTC](https://discuss.elastic.co/t/nested-inner-hits-not-showing-inside-a-function-why/104102/3 "2017-10-16T15:25:05Z")

</div>

Output:

```
{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 0.25811607,
    "hits": [
      {
        "_index": "test",
        "_type": "doc",
        "_id": "1",
        "_score": 0.25811607,
        "_source": {
          "title": "Test title",
          "comments": [
            {
              "author": "kimchy",
              "text": "comment text"
            },
            {
              "author": "nik9000",
              "text": "words words words"
            }
          ]
        }
      }
    ]
  }
}
```

---

<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:** [November 13, 2017, 3:25pm UTC](https://discuss.elastic.co/t/nested-inner-hits-not-showing-inside-a-function-why/104102/4 "2017-11-13T15:25:52Z")

</div>

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