How to get distinct document based on a specific field

In relational database there are two table 1. company and 2. product. One company can have many products.
In elasticsearch I created a type "product" inside the index "my_index". The product document structure is as follows:

"product"  :    {
         "id" :  1,
         "name" : "some name",
        "price": 100,
        "company" : {
              "id" : 405,
             "name" : "company name",
            "search_position" : 1
       }
    }

When I search for product I get multiple document results along with its company object. But problem is when one company has 3 products, all those 3 products are retrieved. I want to get only one product of a particular company i.e distinct product document based on that company.
I tried with aggregation but got result in bucktes and I'm unable to paginate bucktes. Also I need to sort result by company search position.
Please help me. I need to fix it asap.
Thank you.

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