N1QL: Index on all elements in an array?

Hi, is there a way to create an index on all a property for all elements in an array in documents?

For example, I can create an index on property ‘tpnc’ for the first element in my ‘variants’ array like this:

create index tpnc_index on PriceServiceCopy(variants[0].tpnc)

or similarly for second element in array like this

create index tpnc_index2 on PriceServiceCopy(variants[1].tpnc)

And in both cases the index speeds up retrieval vastly

But is there a way to create index including all elements of the array, so that I can search for tpnc irrespective of which element of array in which it occurs?

I’ve experimented with ideas like variants.tpnc, variants[].tpnc, or variants[*].tpnc but none seem to work.

Hi,

This is currently not supported. However, you are at least the second person to ask for this, so we are giving it serious thought.

If we implement this, we will post an update to this question.

Thanks.

Any plan to implement this in the near future? This would help my UNNEST queries . For example with a array field like:
{arrayfield: [{field1: “xx”, field2: “yy”},{…},…]}, and index on arrayfield.field2 would help a query like
select * from b unnest b.arrayfield as a where a.field2=‘yy’.

Hi @Paul_T,

There is significant customer demand for this, so it is on the roadmap after the 4.0 release. We were not able to squeeze it into 4.0.

Gerald