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:
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.
On Monday, November 17, 2014 3:37:00 PM UTC-8, Ben McCann wrote:
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:
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.
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.