Combine SHOULD/MUST condition to filter nested data


(Christian Rütgers) #1

Hello,

after some hours without a reliable solution but headaches I'll ask for some advice.

I have a data set like the one below. Id like to get the "articles" who match the condition of:

product_taxonomy.product_taxonomy_id = (10 OR 20) AND (31 OR 33)

Expected results are the articles with article_id a123, b456 and C789.
I tried a lot, most with nested bool query with nested "must" with two "should's" but I struggle to combine the two OR parts with an AND.

{ 
    "article_id" : "a123",
    "product_taxonomy": [
      {    "product_taxonomy_id": 10 },
      {    "product_taxonomy_id": 31 },
      {    "product_taxonomy_id": 33 }
    ]
},
{ 
    "article_id" : "b456",
    "product_taxonomy": [
      {    "product_taxonomy_id": 10 },
      {    "product_taxonomy_id": 20 },
      {    "product_taxonomy_id": 31 },
      {    "product_taxonomy_id": 32 }
    ]
},
{ 
    "article_id" : "c789",
    "product_taxonomy": [
      {    "product_taxonomy_id": 10 },
      {    "product_taxonomy_id": 21 },
      {    "product_taxonomy_id": 31 },
      {    "product_taxonomy_id": 34 }
    ]
},
{ 
    "article_id" : "x987",
    "product_taxonomy": [
      {    "product_taxonomy_id": 10 },
      {    "product_taxonomy_id": 20 },
      {    "product_taxonomy_id": 32 },
      {    "product_taxonomy_id": 34 }
    ]
},
{ 
    "article_id" : "y654",
    "product_taxonomy": [
      {    "product_taxonomy_id": 11 },
      {    "product_taxonomy_id": 21 },
      {    "product_taxonomy_id": 31 },
      {    "product_taxonomy_id": 33 }
    ]
}

May someone please give me a brief idea on how this might be solved?

Thanks in advance,
Christian


(system) #2