I have some monitors setup in Elasticsearch Kibana, using an extraction query
to fetch the records where griefAttribute > 0
, this query works fine in case all the documents have the said field/attributes, otherwise the monitor fails with below error -
Error -
Error:
Failed fetching inputs:
Failed to execute phase [query], all shards failed;
shardFailures
{
[XayC4jDFF56gYupQ_LdHQ][idx-execution][0]: RemoteTransportException[[62a21ef10083566rgfg4afj163a33e8c69514][<IP_ADDRESS>][indices:data/read/search[phase/query]]];
nested: QueryPhaseExecutionException[Query Failed [Failed to execute main query]];
nested: ScriptException[runtime error];
nested: IllegalStateException[A document doesn't have a value for a field! Use doc[].size()==0 to check if a document is missing a field!];
};
ScriptException[runtime error];
nested: IllegalStateException[A document doesn't have a value for a field! Use doc[].size()==0 to check if a document is missing a field!];;
java.lang.IllegalStateException: A document doesn't have a value for a field! Use doc[].size()==0 to check if a document is missing a field!
Query -
{
"size": 100,
"query": {
"bool": {
"must": [
{
"script": {
"script": {
"source": "doc['griefAttribute'].value > 0",
"lang": "painless"
}
}
},
{
"range": {
"CreatedOn": {
"from": "now-1d/d",
"to": "now/d",
"include_upper": false
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
}
}
Would it be possible for me omit this field existence check error? incorporating doc[].size()==0
condition, something like this?
//Below is a stupid try, that didn't work
{
"script": {
"script": {
"source": "if (doc[griefAttribute].size() > 0) { doc['griefAttribute'].value > 0 }",
"lang": "painless"
},
"boost": 1
}
}
Thank you for taking a look at this.
Best
Prashanth Sripathi