# Include an attribute of top level item on inner\_hits result set?

**URL:** <https://discuss.elastic.co/t/include-an-attribute-of-top-level-item-on-inner-hits-result-set/102199>\
**Category:** Elasticsearch\
**Created:** [September 29, 2017, 1:06am UTC](https://discuss.elastic.co/t/include-an-attribute-of-top-level-item-on-inner-hits-result-set/102199 "2017-09-29T01:06:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dezmathio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dezmathio/32/22629_2.png) [@dezmathio](https://discuss.elastic.co/u/dezmathio)\
**Post date:** [September 29, 2017, 1:06am UTC](https://discuss.elastic.co/t/include-an-attribute-of-top-level-item-on-inner-hits-result-set/102199/1 "2017-09-29T01:06:51Z")

</div>

Here are the mapping, query & result set: [https://gist.github.com/dezmathio/40c397c40c5f7ee864126acc1416e828](https://gist.github.com/dezmathio/40c397c40c5f7ee864126acc1416e828)  
To take the relevant snippets from the link:

part of mapping I care about:

```auto
"vendor_portfolio_items": {
                  "type": "nested",
                  "properties": {
                     "clarifai_item": {
                        "type": "nested",
                        "properties": {
                           "confidence_value": {
                              "type": "float"
                           },
                           "description": {
                              "type": "text",
                              "analyzer": "clarifai_analyzer"
                           }
                        }
                     },
                     "image_url": {
                        "type": "keyword"
                     }
                  }
               }

```

Trying to figure out the best way to include `vendor_portfolio_items.image_url` within the result set I get in my inner\_hits with the `vendor_portfolio_items.clarifai_item` hits.

```auto
"query": {
        "bool": {
          "should": [
            {
            "nested": {
              "path": "vendor_portfolio_items.clarifai_item",
              "query": {
                "match": {
                  "vendor_portfolio_items.clarifai_item.description": "garden"
                }
              },
              "inner_hits": {"size": 5, "sort": [{ "vendor_portfolio_items.clarifai_item.confidence_value": "desc" }]}
            }
          }
          ]

```

and the current result set:

```auto
"inner_hits": {
               "vendor_portfolio_items.clarifai_item": {
                  "hits": {
                     "total": 3,
                     "max_score": null,
                     "hits": [
                        {
                           "_nested": {
                              "field": "vendor_portfolio_items",
                              "offset": 2,
                              "_nested": {
                                 "field": "clarifai_item",
                                 "offset": 0
                              }
                           },
                           "_score": null,
                           "_source": {
                              "description": "backyard",
                              "confidence_value": 0.934
                           },
                           "sort": [
                              0.934
                           ]
                        },
                        {
                           "_nested": {
                              "field": "vendor_portfolio_items",
                              "offset": 1,
                              "_nested": {
                                 "field": "clarifai_item",
                                 "offset": 0
                              }
                           },
                           "_score": null,
                           "_source": {
                              "description": "patio",
                              "confidence_value": 0.821
                           },
                           "sort": [
                              0.821
                           ]
                        },
                        {
                           "_nested": {
                              "field": "vendor_portfolio_items",
                              "offset": 0,
                              "_nested": {
                                 "field": "clarifai_item",
                                 "offset": 0
                              }
                           },
                           "_score": null,
                           "_source": {
                              "description": "outdoors",
                              "confidence_value": 0.779
                           },
                           "sort": [
                              0.779
                           ]
                        }
                     ]
                  }
               }

```

I thought of adding it to the mapping itself so it would be on the same level as the `vendor_portfolio_item.clarifai_item`, but then I would have a duplicate image\_url for every single `clarifai_item` so I would be bloating my index w/ duplicate data.

Any suggestions? cheers

---

<div class="post-metadata">

**Author:** ![dezmathio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dezmathio/32/22629_2.png) [@dezmathio](https://discuss.elastic.co/u/dezmathio)\
**Post date:** [September 29, 2017, 10:09am UTC](https://discuss.elastic.co/t/include-an-attribute-of-top-level-item-on-inner-hits-result-set/102199/2 "2017-09-29T10:09:56Z")

</div>

@perplexa on IRC suggested I just duplicate the fields in the nested document in order to denormalize all the things. I think it might be the easiest approach to take as well.

---

<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 27, 2017, 10:10am UTC](https://discuss.elastic.co/t/include-an-attribute-of-top-level-item-on-inner-hits-result-set/102199/3 "2017-10-27T10:10:20Z")

</div>

Closed on October 27, 2017, 10:10am UTC

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