My requirement. I need to Manually add one more new field called Sub category by writing elastic search query which is not there in the system. with the below criteria.
If my question is "I need to get parcel as soon as possible" AND Category is "Expediate" Then it should be "Express" as subcategory
If my question is "I need parcel after 2 days" AND Category is "Medium" Then it should be "MIDLEVEL" as subcategory
If my question is "I need today itself " AND Category is "Super fast " Then it should be "HIGHER" as subcategory
Below should be my output
Need Questions field aggregation
Need New field as subcategory aggregation
Expected result : aggregate the data such that there's a new column which depends on the original Question
You can put the custom logic you noted down in your question into painless code and return the appropriate subcategory string, then add it as a scripted field named "subcategory" in the index pattern. Once you've done that, you can use it like any other field (e.g. to do a terms aggregation on it)
Would you mind sharing one example for scripted field that to put static 10 questions
I tried this below query: but not working
if (doc['question'].value == 'I need to get parcel as soon as possible','Parcel required as soon as possible') AND Category == 'Expediate'{
return 'Express';
}else if (doc['question'].value == 'I need parcel after 2 days','Parcel required after 2 days') AND Category ==' Medium' {
return 'MIDLEVEL';
}else if (doc['question'].value == 'I need today itself','parcel required today at any cost') AND Category ==' HIGHER' {
return 'MIDLEVEL';
}
What exactly isn't working? You can use "Get help with the syntax and preview the results of your script." link to get a preview for 10 documents and the return value. This can be helpful to debug your script whether it's doing the right thing.
if (doc['question.keyword'].value == 'I need to get parcel as soon as possible','Parcel required as soon as possible') AND Category == 'Expediate'{
return 'Express';
}else if (doc['question.keyword'].value == 'I need parcel after 2 days','Parcel required after 2 days') AND Category ==' Medium' {
return 'MIDLEVEL';
}else if (doc['question.keyword'].value == 'I need today itself','parcel required today at any cost') AND Category ==' HIGHER' {
return 'MIDLEVEL';
}
I am getting the following error. Do no how to write correct query format.
Your syntax is pretty off - if you have multiple conditions, list them like this:
if ((doc['question.keyword'].value == 'I need to get parcel as soon as possible' || doc['question.keyword'].value == 'Parcel required as soon as possible') && doc['category.keyword'].value == 'Expediate') { //...
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.