I am new when it comes to Elasticsearch. I have an endpoint:
http://localhost:8000/v1/scholarship
This returns all scholarships in the database. I can add a filter:
http://localhost:8000/v1/scholarship?institution=Michigan State
This will return all scholarships associated with a specific institution (in this case, Michigan State)
My scholarship model has an institution field that defaults to an empty list if no institution is affiliated:
"institution" : [],
How would I go about filtering all scholarships that have no institutions?
I tried this query but all the scholarships are returned (since there was no match)
http://localhost:8000/v1/scholarship?intitution=[]
Any ideas? I was thinking of creating a new end point, but that seems to defeat the purpose of using filters / Elasticsearch
You can use an Exists Query to look for empty fields:
GET localhost:8000/v1/scholarship/_search
{
"query": {
"bool": {
"must_not": {
"exists": {
"field": "scholarship"
}
}
}
}
}
This matches the below fields:
{ "scholarship": null }
{ "scholarship": [] }
{ "scholarship": [null] }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With