So I have a field that's basically just an array of tags and what I want to do is filter out any documents where the length of that tags array (i.e. the number of tags in the field) is greater than some specific number. This seems like it should be pretty simple but I've pored over the docs and I can't seem to find anything in the query DSL for querying based on a field's term count. I know you could probably achieve this using a script_score combined with min_score, but that feels like it wouldn't be very performant and I also just want to make sure I'm not missing the "right" way to do something like this.
Assuming there is a way to do this that isn't script_score, I'm also wondering if there's a way to filter based on the number of tags in a field that don't match any term in a terms query. In other words I need to somehow filter based on (doc['tags'] - query['tags']).length. Any help would be much appreciated.