Include an attribute of top level item on inner_hits result set?


(Josiah Anjos) #1

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

part of mapping I care about:

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

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

"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


(Josiah Anjos) #2

@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.


(system) #3

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