Hello, I am just new to Kibana query. I am trying to query a field, which is a list of objects
"leadStages" : [
{
"leadStage" : 1,
"inTime" : 1597832744832,
"outTime" : 1597946057541
},
{
"outTime" : 1598083851243,
"inTime" : 1597946057541,
"leadStage" : 2
},
{
"inTime" : 1598083851243,
"outTime" : 0,
"leadStage" : 3
}
],
In the above document field i.e. leadStages, I would like to fetch last element and check "inTime" value. The query I wrote
{
"query": {
"bool": {
"filter": {
"script": {
"script": {
"source": """
def stages = doc['leadStages'];
def arrLen = stages.length-1;
return (stages[arrLen].inTime == 0);
""",
"lang": "painless",
"params": {
"param1": 5
}
}
}
}
}
}
}
But the error I got is
"caused_by" : {
"type" : "illegal_argument_exception",
"reason" : "No field found for [leadStages] in mapping"
}
I then changed the query to
"source": """
def stages = doc['leadStages.inTime'];
def arrLen = stages.length-1;
return (stages[arrLen].value == 0);
""",
This time the error was
"type" : "illegal_state_exception",
"reason" : "A document doesn't have a value for a field! Use doc[<field>].size()==0 to check if a document is missing a field!"
I have already spent couple of hours on this. Your help would help a lot.