I am trying to sum two integer values as following, but I am getting compile error. I am not much familiar with painless syntax.
if (doc['allocated.raw'].value == 'Physically') {
int cpu = 0
cpu = doc['total_cpu'].value*2
} else {
cpu = 0
}
if (doc['server_type.raw'].value == 'Virtual') {
int vcpu = 0
vcpu = vdoc['total_cpu'].value
} else {
cpu = 0
}
@Gurveer_Singh Try this out and see if it gets you what you were looking for
long cpu = 0;
long vcpu = 0;
if (doc['allocated.raw'].value == 'Physically') {
cpu = doc['total_cpu'].value*2;
}
if (doc['server_type.raw'].value == 'Virtual') {
vcpu = doc['total_cpu'].value;
}
return cpu + vcpu;
A couple things to note:
the use of semi-colons
cpu and vcpu have to be declared outside of the if statements if they're going to be used in the return
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.