If you are using default mappings st2 will be analysed and not available as a doc value, which is what you are trying fo access in the script. st2.keyword is however stored as doc values, which is why you can access it using the doc[] notation.
It looks like either the mapping has changed or that not all documents contain the field. If it is the latter you will need to guard against this in the script.
actually i deleted all the indexes and documets and then created new index today,what should i do?
Also I cannot see .keyword values for some of the fields in available fields
Your mappings or index template will determine whether the keyword subfield exists or not. If not all documents contain the field you may need to try something like this, which return a default value of 0 if the field is not found:
int val = 0; if(!doc['st2.keyword'].empty) { val = Integer.parseInt(doc['st2.keyword'].value) * 8.0 ) / 900; } return val;
Since you know if the field is there at index time, why not create an additional field with the correct value before you index the document. That way you perform the calculation once instead of for every document and every query, which will likely give better performance.
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.