# How to filter only specific objects from nested array in elasticsearch?

**URL:** https://discuss.elastic.co/t/how-to-filter-only-specific-objects-from-nested-array-in-elasticsearch/310691
**Category:** Elasticsearch
**Tags:** eql-elastic-query-language
**Created:** [July 26, 2022, 9:55pm UTC](https://discuss.elastic.co/t/how-to-filter-only-specific-objects-from-nested-array-in-elasticsearch/310691 "2022-07-26T21:55:35Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Munam\_Tariq](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/munam_tariq/32/101721_2.png) [@Munam\_Tariq](https://discuss.elastic.co/u/Munam_Tariq)
#### Post date: [July 26, 2022, 9:55pm UTC](https://discuss.elastic.co/t/how-to-filter-only-specific-objects-from-nested-array-in-elasticsearch/310691/1 "2022-07-26T21:55:35Z")

</div>

```auto
{
  "sku_id": 12,
  "product_id": 1,
  "product_name": "coca-cola 1.5 L",
  "category_name": "beverages",
  "brand_name": "coca cola",
  "sellers": [
    {
      "seller": 1,
      "price": 50
    },
    {
      "seller": 2,
      "price": 40
    },
    {
      "seller": 3,
      "price": 30
    }
  ]
}

```

I have this type of document. I want to write a query to select product but only that seller in sellers array who have lowest value of price and ignore all other sellers in result.  
My expected output is

```auto
{
  "sku_id": 12,
  "product_id": 1,
  "product_name": "coca-cola 1.5 L",
  "category_name": "beverages",
  "brand_name": "coca cola",
  "sellers": [
    {
      "seller": 3,
      "price": 30
    }
  ]
}

```

I can use aggregate but aggregation adds separate aggregation object at the end of result. Aggregation will not keep sellers array part of product object. I want exactly same response as i mentioned above.

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [August 4, 2022, 7:08am UTC](https://discuss.elastic.co/t/how-to-filter-only-specific-objects-from-nested-array-in-elasticsearch/310691/2 "2022-08-04T07:08:07Z")

</div>

Elasticsearch can as far as I know not only return selected nested documents like in your example, so this is a transformation you will need to perform yourself on the result.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [September 1, 2022, 7:09am UTC](https://discuss.elastic.co/t/how-to-filter-only-specific-objects-from-nested-array-in-elasticsearch/310691/3 "2022-09-01T07:09:00Z")

</div>

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