I am trying to create some report filters where the user can search for profiles using any fields on the report. For example: search for any profile with firstname
that starts with ann
and grade
that starts with vi
etc.
Here is a query I have written so far:
{
from: 20,
size: 20,
query: {
filtered: {
query: {
match_all: [ ]
},
filter: {
bool: {
must: [
{
prefix: {
firstname: "ann"
}
},
{
prefix: {
grade: "vi"
}
}
]
}
}
}
},
sort: {
grade: {
order: "asc"
}
}
}
If I remove one child of must
(in the bool
filter), it works. But it doesn't return any results once I use more than one filters and I need to be able to use any number of entries in there.
Also, if I use should
instead of must
, it works. I'm not sure if I'm misunderstanding the logic, but to my understanding (in this case) must
should return ONLY results with firstname
that starts with ann
and grade
that starts with vi
.
They do exist, but this query just doesn't find them.
Am I missing something here?
Thanks