Query: Search for files based on the number of values in an array
Query Template
| name of the field you want to search in |
| Use an operator (<, >, <=,>=,==,!=) |
| The number or count in relation to the operator |
{
"query": {
"bool": {
"must": [
{
"exists": {
"field": "<field_name>"
}
}
],
"filter": {
"script": {
"script": {
"source": "doc['<field_name>.keyword'].values.size() <operator> <number>",
"lang": "painless"
}
}
}
}
}
}
Example
Usecase: “I want to find all files in the index that have more than 2 rot_trivial values”
Query
{
"query": {
"bool": {
"must": [
{
"exists": {
"field": "rot_trivial"
}
}
],
"filter": {
"script": {
"script": {
"source": "doc['rot_trivial.keyword'].values.size() > 2",
"lang": "painless"
}
}
}
}
}
}