I am using Kibana and have an index that looks like this
GET index_name/
{
"index_name": {
"aliases": {},
"mappings": {
"json": {
"properties": {
"scores": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
I would like to get the length of the scores array (ie, how many text elements it has in it) for each record, with the end goal of filtering out records whose length is greater than or equal to 20. So far, I'm able to identify (highlight) each of the records that IS "20" but can't seem to build a filter that I could then turn into a boolean value (1 for true) for later use / summing records that satisfy the condition. I am putting this into the Discover Panel's filter, after clicking on 'Edit Query DSL':
{
"query": {
"match": {
"scores": {
"query": "20",
"type": "phrase"
}
}
}
}
EDIT: an example of this field in the document is:
scores:12, 12, 12, 20, 20, 20
In the table tab view, it has a t next to it, signifying text. The length of this field varies anywhere from 1 to over 20 items from record to record. I also don't know how to get the length of this field (only) returned to me with a query, but I have seen some other answers that suggest something like this (which produces an error for me):
"filter" : {
"script" : {
"script" : "doc['score'].values.length > 10"
}
}
scoresfield and array of text values? Can you share an example?scoreis of typetextthen you can't usedoc['score'].values.length. Instead if there is a sub-field of typekeywordthen you can usedoc['score.keyword'].values.length.