# How can I get only products that have at least one trusted seller?

**URL:** https://discuss.elastic.co/t/how-can-i-get-only-products-that-have-at-least-one-trusted-seller/111344
**Category:** Elasticsearch
**Created:** [December 12, 2017, 1:20pm UTC](https://discuss.elastic.co/t/how-can-i-get-only-products-that-have-at-least-one-trusted-seller/111344 "2017-12-12T13:20:50Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Claudio\_Ranieri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/claudio_ranieri/32/25393_2.png) [@Claudio\_Ranieri](https://discuss.elastic.co/u/Claudio_Ranieri)
#### Post date: [December 12, 2017, 1:20pm UTC](https://discuss.elastic.co/t/how-can-i-get-only-products-that-have-at-least-one-trusted-seller/111344/1 "2017-12-12T13:20:51Z")

</div>

I have documents with nested seller as shown below:

{  
name: Product A,  
sellers: [  
{id: 1011},  
{id: 2020}  
]  
},  
{  
name: Product B,  
sellers: [  
{id: 1011},  
{id: 6050}  
]  
},  
{  
name: Product C,  
sellers: [  
{id: 3013}  
]  
},  
{  
name: Product D,  
sellers: [  
{id: 4050},  
{id: 5051}  
]  
}

I have a blacklist of sellers. For example, the seller with id=1011 and id=2020 are blacklisted.  
How can I get only products that have at least one trusted seller?  
I want a return as show below:

{  
name: Product B,  
sellers: [  
{id: 6050}  
]  
},  
{  
name: Product C,  
sellers: [  
{id: 3013}  
]  
},  
{  
name: Product D,  
sellers: [  
{id: 4050},  
{id: 5051}  
]  
}

The "Product A" must not appear because it does not have any trusted seller.  
The "Product B" must appear (because has one trusted seller) but excluding the seller with id=1011 (it is blacklisted)

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [December 12, 2017, 5:26pm UTC](https://discuss.elastic.co/t/how-can-i-get-only-products-that-have-at-least-one-trusted-seller/111344/2 "2017-12-12T17:26:51Z")

</div>

This is not something that Elasticsearch allows to do easily.

One option I can think of requires to map sellers as a `nested` object and then use a `nested` query to find all trusted sellers and join the associated products. But this is a bit heavy since nested documents have some cost.

---

<div class="post-metadata">

### Author: ![Claudio\_Ranieri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/claudio_ranieri/32/25393_2.png) [@Claudio\_Ranieri](https://discuss.elastic.co/u/Claudio_Ranieri)
#### Post date: [December 12, 2017, 5:53pm UTC](https://discuss.elastic.co/t/how-can-i-get-only-products-that-have-at-least-one-trusted-seller/111344/3 "2017-12-12T17:53:19Z")

</div>

Hi @jpountz,  
Would you show me an example?

---

<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: [January 9, 2018, 5:53pm UTC](https://discuss.elastic.co/t/how-can-i-get-only-products-that-have-at-least-one-trusted-seller/111344/4 "2018-01-09T17:53:21Z")

</div>

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