title: Querying nested objects in Elasticsearch
body: <p>I have a Product-Merchant mapping which looks like the following</p>
  
  <pre><code>  catalog_map = {
  
          "catalog": {
              "properties": {
                  "merchant_id": {
                      "type": "string",
                  },
                  "products": {
                      "type": "object",
                  },
                  "merchant_name" :{
                      "type" : "string"
                  }
              }
          }
      }
  </code></pre>
  
  <p>"product" has objects, say , product_id , product_name , product_price. Products and merchants are mapped, such that : </p>
  
  <pre><code>    for merchant in Merchant.objects.all() :
  
          products = [{"product_name" : x.product.name, "product_price" : x.price, "product_id" : x.product.id , "product_category" : x.product.category.name} for x in MerchantProductMapping.objects.filter(merchant=merchant)]
  
          tab = {
              'merchant_id': merchant.id,
              'merchant_name': merchant.name,
              'product': products
              }
  
         res = es.index(index="my-index", doc_type='catalog', body=tab)
  </code></pre>
  
  <p>The data gets indexed smoothly, in the desired form. Now, when I query the data from given index, I do it in the following way : </p>
  
  <pre><code>GET /esearch-index/catalog/_search
  { 
  "query": {
  "bool" :{
      "must": [
         {"match": {
            "merchant_name": {
                "query": "Sir John"
            }
         }}], 
         "should": [
            {"match": {
               "product_name": {
                   "query": "Vanilla"
               }
            }}
         ]
      }}
  </code></pre>
  
  <p>This query gives me the result of all the products in the index with merchant name "Sir John" . However, <strong>I want it to return the details of the product "Vanilla" sold by "Sir John" instead.</strong></p>
  
  <p>On someone's recommendation, I used "_source" while querying, but that doesn't help. </p>
  
  <p><strong>How can I single out the information of one single object from the entire "catalog" index of the merchant?</strong></p>