Hi,
I am using couchbase 4.0.
As per what I could serach & read, there is no way to index arrays & nested arrays in couchbase 4.0.
We have a no. of documents which have arrays & nested arrays as data.
Doing a N1QL (using JOIN & UNNEST) for these type of documents takes a long time for the query to return results. The Couchbase Community Edition 4.5, which supports array indexing is not yet available.
Querries
Q1) Is there a way to a) index an array b) index individual array elements?
Q2) If there is no way to index array & nested array, what is the suggested change in json document structure (as below) to get data faster?
Q3) I am using the following N1QL which takes a very long time to return results, is there a better way for N1QL, I have created a GSI index on the field "type " on both types of documents mentioned below.
SELECT bkt1.type type1, bkt2.type type2, nwTrans.nwId, nwTrans.nwTranGroupId nwTransGrpId, nwTrans.tranId, nwTranGroups.nwId grpNwId, nwTranGroups.nwTranGroupId,
nwTranGroups.nwTranGroupStops
FROM devl bkt1
UNNEST bkt1.nwTrans
LEFT JOIN devl bkt2
ON KEYS ânwTranGroups::â || TO_STRING(nwTrans.tranId)
UNNEST bkt2.nwTranGroups nwTranGroups
WHERE bkt1.type = 'transâ
AND bkt2.type = 'tranGroupsâ
AND nwTrans.nwId = 1
AND nwTrans.tranId = 12
AND nwTranGroups.nwId = 1
AND nwTranGroups.nwTranGroupId = 11
Q4) When is the Couchbase 4.5 Community Edition expected to be released?
The following are my json document structure, arrays in documents are in bold:
document 1 - nw::1
{
âtypeâ: âtransâ,
ânwTransâ: [
{
ânwIdâ: 1,
ânwTranGroupIdâ: 1,
âtranIdâ: 1
},
{
ânwIdâ: 1,
ânwTranGroupIdâ: 2,
âtranIdâ: 2
},
{
ânwIdâ: 1,
ânwTranGroupIdâ: 3,
âtranIdâ: 3
},
{
ânwIdâ: 1,
ânwTranGroupIdâ: 3,
âtranIdâ: 6
}
]
}
document 2 - nwTranGroups::1
{
âtypeâ: âtranGroupsâ,
ânwTranGroupsâ: [
{
ânwIdâ: 1,
ânwTranGroupIdâ: 1,
ânwTranGroupStopsâ: [
{
âminSinceFirstStopâ: 0,
âminSincePrevStopâ: 0,
ânwGroupStopNumâ: 1,
ânwStopNumâ: 16
},
{
âminSinceFirstStopâ: 3,
âminSincePrevStopâ: 3,
ânwGroupStopNumâ: 2,
ânwStopNumâ: 17
},
{
âminSinceFirstStopâ: 8,
âminSincePrevStopâ: 5,
ânwGroupStopNumâ: 3,
ânwStopNumâ: 18
}
],
âstartNwStopNumâ: 16,
âtravelDurationInMinâ: 21
},
{
ânwIdâ: 1,
ânwTranGroupIdâ: 2,
ânwTranGroupStopsâ: [
{
âminSinceFirstStopâ: 0,
âminSincePrevStopâ: 0,
ânwGroupStopNumâ: 1,
ânwStopNumâ: 12
},
{
âminSinceFirstStopâ: 3,
âminSincePrevStopâ: 3,
ânwGroupStopNumâ: 2,
ânwStopNumâ: 13
},
{
âminSinceFirstStopâ: 6,
âminSincePrevStopâ: 3,
ânwGroupStopNumâ: 3,
ânwStopNumâ: 14
}
],
âstartNwStopNumâ: 12,
âtravelDurationInMinâ: 36
},
{
ânwIdâ: 1,
ânwTranGroupIdâ: 3,
ânwTranGroupStopsâ: [
{
âminSinceFirstStopâ: 0,
âminSincePrevStopâ: 0,
ânwGroupStopNumâ: 1,
ânwStopNumâ: 21
},
{
âminSinceFirstStopâ: 3,
âminSincePrevStopâ: 3,
ânwGroupStopNumâ: 2,
ânwStopNumâ: 22
}
],
âstartNwStopNumâ: 21,
âtravelDurationInMinâ: 36
}
]
}
Regards,
Sachin Vyas.