Fetch Related Data w/o Applying Query inside an Aggregation

Here is what my data looks like:

Store Index

 {
  "store_id": integer,
  "store_name": string,
  "address": text
}

Product Index

 {
  "product_id": integer,
  "product_name": string,
  "product_sku": string,
  "store_id" : integer,
  "store_name" : string
}

I've already tried to bring the store and products but separately. Have used alias for common fields too to get store and product names. There is also a problem that the search query is also applied on SKUs which I do not want.

What I'am expecting is a query which brings the aggregated store as well as the products in single hit. Which may look like below:

Expected Results (Rough Idea)

 {
  "results": [
    {
      "type": "store",
      "name": "Some chicken store",
      "latest_SKUs": ["45345435435", "5654645645"]
    },
     {
      "type": "product",
      "name": "Spicy Nuggets",
      "latest_SKUs": ["4asda5435435"] //Only single SKU in case of products
    },
     {
      "type": "store",
      "name": "Shoe Store",
      "latest_SKUs": ["46621278136", "613187979"]
    }

    ]
}

@elasticpatrick Please specify your product and store index attributes and what have you already tried so that we can get insight in your data to help you with it.

Here, I have updated my data which look like above

What you are looking to do is basically a join between two indices. Elasticsearch does not support joins so you will likely need to denormalize your data to run the query you specified.

Thanks for the answer. But can you please suggest me the approach of how to do it . As you must already got the idea of how my index must be looked like.

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