CREATE INDEX `Idx_ArrayIndexingTest`
ON `test_bucket`(docType, tags, DISTINCT ARRAY t FOR t IN tags END, title)
WHERE docType="Test";
If I run this query:
SELECT META().id from `test_bucket`
WHERE docType="Test";
…I get this result:
[
{},
{
"id": "102"
},
{
"id": "103"
}
]
As soon as I add an entry into the empty array in doc 101, I get all three IDs back in the query result as expected. Then if I remove again (to leave an empty array), the query result returns back to the above. A null for the array (rather than an empty array) fixes the problem, but that isn’t ideal. If I select a property other than META().id it’s fine too, it’s just the document ID that doesn’t appear in the result.
I’m running 4.5.0-2601 Enterprise Edition (build-2601) on Server 2012 R2.
As you can see, the title field isn’t in the results for the doc that has an empty array. I’ve spotted this because an ORDER BY title in my real world data was placing some docs right at the beginning incorrectly (I assume because the query engine can’t see the title to determine sort order on these docs either).
As in 4.5, assigning a NULL to the array property (rather than an empty array) or adding at least one entry resolves the issue.