4

I want to do a statistical facet on one of my arrays. I hope something like

"script" : "doc['myField'].doubleValue

or

"script" : "doc['myField'].count

would work. I havent found any array count method in mvel and I don't even know if accessing the array field in a script actually gives me the array.

Alden
  • 312
  • 5
  • 13
  • Have a look here: http://stackoverflow.com/questions/12733351/how-do-i-sort-the-search-results-according-to-the-number-of-items-in-elasticsear/12734613#12734613 – javanna Mar 15 '13 at 17:42

1 Answers1

5

I might have it. It seems I need to count a field inside the array instead of the array itself. This might just be because all I have are arrays of objects.

"script" : "doc['arrayField.objectField'].values.length"
Alden
  • 312
  • 5
  • 13
  • Ha, I did this and it totally killed my cluster. Maybe there is a way to do this with better performance. – Alden Mar 15 '13 at 17:59
  • It killed your cluster because it loaded all values of this field into memory and before version 0.90 elasticsearch was using quite inefficient structure to keep values for multi-valued fields in memory. So, you have a few options here: upgrade to 0.90.0.Beta1, use _fields instead of doc if this field is stored or to index the length of the array as another field. The last solution is the best in my opinion. – imotov Mar 16 '13 at 00:15