Detect exact field that matched the text

Given this document:

{  
   "id":123,
   "name":"amazing dress",
   "variations":[  
      {  
         "sku":456,
         "name":"amazing dress red",
         "price":12.42
      },
      {  
         "sku":789,
         "name":"amazing dress blue",
         "price":13
      }
   ]
}

How could i detect what SKU the query hit? This is soooo dammm important for me.
Usually my query is something like this:

{  
   "query":{  
      "multi_match":{  
         "fields":[  
            "name",
            "variations.name"
         ],
         "query":"red dress"
      }
   }
}

So i'm gonna hit that document, but, how to discover the SKU that really hit the document?

Each SKU needs its own document. You can use nested object if you want to but it is often simpler to just build documents like

{  
    "product": 123,
    "name": "amazing dress",
    "sku":789,
    "name":"amazing dress blue",
    "price":13
 }

You can think of nested is a fancy way to automatically build all those documents.

But this gonna lead to other problems. If a given product have multiple SKU and they are indexed as multiple documents, when a query is executed, the same item could return multiple times, but, in fact, its just a single product that must return, the sku separation is just a abstraction.

What i'm trying to say is, in the application, only the base product should be displayed, if the user click that product, inside the product page it show the skus, like in almost all ecommerces.

This thing i'm trying to do is to solve a problem when users ask for 'black dress' and the image displayed is a 'white dress', but there is a inner sku of that product that is white. With this the app can show the correct sku without the user need to enter the product to see if has the property it's searching.

Another thing that multiple sku documents generate is the incorrectness of count, aggregations, etc...

I'm not familiar with nested objects, but don't seems that if gonna help to identify whatis the sku the query hited, it may help in accuracy.

This sounds more like the traditional use case for parent/child documents actually. Have a look at those as well.

You might be looking for inner hits, which will only return the nested
objects that are matched by a nested query:

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-inner-hits.html

Ivan