kambiu
(Kambiu)
February 8, 2017, 10:03am
1
if (doc.containsKey('fieldname') {
return 0;
}
else {
return 1;
}
The above code return compile error in kibana and ES 5.2.0.
What is the correct syntax of painless to check if a field exists?
My solution:
After searching a while, find that
doc['field_name'].empty
A boolean indicating if the field has no values within the doc.
will return true if the field does not exist on the records.
Ref
1 Like
ppisljar
(Peter Pisljar)
February 8, 2017, 4:38pm
2
what about if (doc['fieldname'])
?
kambiu
(Kambiu)
February 9, 2017, 2:30am
3
if (doc['fieldname'])
It return a warning "Courier Fetch: 5 of 5 shards failed." when I search *. And no result return.
Update:
The following error found in elasticsearch.log
Caused by: java.lang.ClassCastException: org.elasticsearch.index.fielddata.ScriptDocValues$Strings cannot be cast to java.lang.Boolean
1 Like
system
(system)
Closed
March 9, 2017, 2:31am
4
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
LeeDr
(Lee Drengenberg)
May 26, 2017, 5:20pm
5
Did you solve your issue? I just posted a response here that might help you;
Hi Chris,
I think a scripted field might help. Here's an experiment I did.
I put this data using Kibana dev console. Each doc has a name but in a different field;
PUT /discuss/test/1
{
"date" : "2017-05-26T00:01:00",
"name" : "Lee"
}
PUT /discuss/test/2
{
"date" : "2017-05-26T00:02:00",
"firstName" : "Bob"
}
PUT /discuss/test/3
{
"date" : "2017-05-26T00:02:30",
"fullName" : "Bart Simpson"
}
It looks like this in Discover;
[image]
Obviously I can already sea…