I want to filter my search results by using a script filter, to make sure all documents with a specific phonenumber field length are not showed up in the results:
"query": {
"bool": {
"filter": {
"script": {
"script": {
"source": "doc['identities.phonenumber.keyword'].toString().length() > params.min"
"params": {
"min": 6
}
}
}
}
}
}
The problem is that "identities" is an array of objects. So if there are two objects, each containing a "phonenumber" which length is equal to 4, it still shows up in the results (4 + 4 = 8).
Any thoughts how to fix this?