Nested Inner Hits not showing inside a function, why?

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

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"
    }
  }
} 

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"
            }
          ]
        }
      }
    ]
  }
}

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