I am trying to count Array Elements across all documents and sum them up, but I keep getting this error: "No field found for [offers] in mapping with types [ ]"
Mappings
{
"mappings": {
"properties": {
"offers": {
"properties": {
"name": { "type": "text" },
"id": { "type": "keyword" }
}
},
"requirements": {
"properties": {
"name": { "type": "text" },
"id": { "type": "keyword" }
}
}
}
}
}
Query
{
"aggs": {
"count_offers": {
"sum": {
"script" : {
"lang": "painless",
"source": "doc['offers'].value.length"
}
}
},
"count_requirements": {
"sum": {
"script" : {
"lang": "painless",
"source": "doc['requirements'].value.length"
}
}
}
}
}
In the end I want to be able to retrieve the total number of offers or requirements.
I suspect that painless cannot deal with the field "offers" as an array. But this confuses me, as the ES documentation states that there is no dedicated array type (over here).
I found some related topics here and on Stackoverflow, but I could not solve my problem with them.
Thanks for any help