Hi,
I have a document which has an array of objects as a field. I'd like to
count the length of this array filtering on an attribute of the objects,
but am having a really hard time.
E.g. I'd like to use a script to create a computed field with a value of 3
for this document:
{
myfield: [{
value: 'a'
}, {
value: 'b'
exclude: true
}, {
value: 'c'
}, {
value: 'd'
}]
}
There are two general approaches I've thought of. The first would be:
ctx._source['newfield'] = ctx._source['myfield'].values.size() -
ctx._source['myfield.exclude'].values.size();
The second approach could be something like:
i = 0; for (value in ctx._source['myfield']?.values) { if(!value.exclude) {
i++; } }; ctx._source['newfield'] = i
Do either of these sound like an approach I should focus on over the other?
Is one likely to be much faster or impossible? I've not had any luck with
either route thus far.
Thanks,
Ben
--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/ec6d65b7-82dd-465c-8b00-98127b2666ef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.