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

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)

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.

Hi @jpountz,
Would you show me an example?

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