Painless: How to simulate a hashmap as a variable for painless lab?

Hi,
I've got below painless snippet

// define sample data as hashmap (similar to Elastic output)
def buy_list = ' [{doc_count=13, category={buckets=[{doc_count=11, key=apple}, {doc_count=12, key=mango}, {doc_count=13, key=mango}, {doc_count=14, key=mango}]}, key=fruits} , {doc_count=34, category={buckets=[{doc_count=23, key=carrot}, {doc_count=41, key=beet}, {doc_count=21, key=potato}, {doc_count=21, key=pepper}]}, key=vegetables}]' ;

// Method to iterate and return lh_list
List lh_list = new ArrayList();
for (Map l1: buy_list) {
  for (Map l2: l1.category.buckets) {
    lh_list.add(l2.key);
  }
}
return lh_list

But the above code is not correct as the "definition" of the Hashmap is not working. All I want to put is sample data in format we get within watcher, so want to simulate in painless lab
The above logic works in watcher when the data comes as ctx.payload... format

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.