Hello there, I'm pretty new to the ES stack and I'm actually replacing a Mongo text query by ES.
I need some help to build a query : I need to search in text indexed fields of an index BUT I also want to be able to filter the results by 3 fields (which are actually ids so no chance of conflict with other fields). I'll try to explain what problem I'm facing :
Let's say that those fields are carts where I can put items, so the carts will be array of strings. I want to be able to filter the results by docs who have some items in one of the carts. For example, I want the docs that only have carts that possess 'Salt' AND 'Sugar', but 'Salt' can be in _cart1 and 'Sugar' in _cart3.
I already have a query that's close, the only notion I'm missing is : is it possible to have a filter that will have a MUST which contains several SHOULD ?
This is the query that I have for now :
query: {
bool: {
must: {
query_string: {
fields: [
'aField^5',
'anotherOne^10',
'lastField',
],
query: '*',
},
},
filter: [
{
bool: {
should: [
{
terms: {
_cart1: [
'Sugar',
'Salt',
],
},
},
{
terms: {
_cart2: [
'Sugar',
'Salt',
],
},
},
{
terms: {
_cart3: [
'Sugar',
'Salt',
],
},
},
],
},
},
],
},
},