# How to return only inner hits in nested field

**URL:** https://discuss.elastic.co/t/how-to-return-only-inner-hits-in-nested-field/198842
**Category:** Elasticsearch
**Created:** [September 10, 2019, 7:53am UTC](https://discuss.elastic.co/t/how-to-return-only-inner-hits-in-nested-field/198842 "2019-09-10T07:53:24Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![salihklc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/salihklc/32/79520_2.png) [@salihklc](https://discuss.elastic.co/u/salihklc)
#### Post date: [September 10, 2019, 7:53am UTC](https://discuss.elastic.co/t/how-to-return-only-inner-hits-in-nested-field/198842/1 "2019-09-10T07:53:24Z")

</div>

Hi everyone,  
Just like I mention in the title, I have data set with the mapping below which has nested field. I am trying to get data with inner hits which are match with the written query.

If I write "\_source":false at the top level of the query this will only return inner hits. ( [example](https://stackoverflow.com/questions/35589084/elasticsearch-return-only-nested-inner-hits) )

Also in the [documents](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html#request-body-search-inner-hits) says if I write inner\_hits in the nested query part this will return only hit which are matched the query.

```
    {
  "mapping": {
    "properties": {
      "ekuNo": {
        "type": "long"
      },
      "idx": {
        "type": "long"
      },
      "logInsertionDate": {
        "type": "date"
      },
      "receiptDate": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "receiptDateTime": {
        "type": "date"
      },
      "receiptPayment": {
        "type": "nested",
        "properties": {
          "amount": {
            "type": "double"
          },
          "amountTL": {
            "type": "double"
          },
          "appBankColor": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "appBankName": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "appBkmId": {
            "type": "integer"
          },
          "appTeliumAppId": {
            "type": "integer"
          },
          "cardBankColor": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "cardBankName": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "cardTeliumAppId": {
            "type": "integer"
          },
          "cashAmount": {
            "type": "double"
          },
          "creditAmount": {
            "type": "double"
          },
          "ekuNo": {
            "type": "long"
          },
          "flags": {
            "type": "integer"
          },
          "groupByAppBankData": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "groupByCardBankData": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "groupByPaymentType": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "logInsertionDate": {
            "type": "date"
          },
          "paymentTypeDesc": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "receiptDateTime": {
            "type": "date"
          },
          "seqNo": {
            "type": "long"
          },
          "serialNo": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "type": {
            "type": "integer"
          },
          "zSeqNo": {
            "type": "long"
          }
        }
      },
      "receiptTime": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "seqNo": {
        "type": "long"
      },
      "serialNo": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "zSeqNo": {
        "type": "long"
      }
    }
  }
}

```

Also Query is

```
    get receiptreport_direct/_search
{"from": 0 ,"size": 10, "sort" : [],"_source":false, "query": { "bool" : { "must": [{ "range": { "receiptDateTime": { "lte": "2018-02-01" } } },{ "range": { "receiptDateTime": { "gte": "2018-01-01" } } }, { "nested": { "path" : "receiptPayment", "query" : { "bool" : { "must" : [{ "script": { "script": "doc['receiptPayment.cardTeliumAppId'].value != doc['receiptPayment.appTeliumAppId'].value" } }] } }, "inner_hits":{} } }], "must_not": [], "should": [], "filter": [] } } }
```

---

<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: [October 8, 2019, 8:07am UTC](https://discuss.elastic.co/t/how-to-return-only-inner-hits-in-nested-field/198842/2 "2019-10-08T08:07:13Z")

</div>

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