Couchbase N1QL Array Indexing for Deep Nested JSON Array

n1ql
query
index

#1

The communication field below is a part of a larger json file. The field i am trying to index is code

"communication": [
 {
  "language": {
    "coding": [
      {
        "code": "en-US",
        "system": "http://hl7.org/fhir/ValueSet/languages",
        "display": "English (United States)"
      }
    ]
  }
}
]

I have written this Create Index code and its executing well , No errors

create index `patient_communication_language_coding_code` on
 neuron(distinct array 
            (distinct array c.code for c in v.language.coding end)
    for v in communication end)

but when I try to query It doesn’t select the Index or Using it …

select * from `neuron` as r use index(patient_communication_language_coding_code)
where any comm in r.communication satisfies
   any coding in comm.language.coding satisfies coding.code = 'en-US'
   end
end;

The above query is valid. I have previously indexed on array of array in couchbase but this situation is array.object.array.object which is the code field. There are no syntax error . I am i doing something wrong or it is not possible to index array this deep?


#2

which version of CB do you use?
it is works on CB Version: 4.6.3-4136 Enterprise Edition (build-4136)


#3

@atom_yang
I am using Version: 4.6.1-3652 Enterprise Edition (build-3652) on Docker with 2 nodes with same version


#4

In 4.6.1 The variables in ANY clause needs to match with variables used in index. In 4.6.2+ variables can be arbitrary.
https://developer.couchbase.com/documentation/server/current/n1ql/n1ql-language-reference/indexing-arrays.html

select * from `neuron` as r use index(patient_communication_language_coding_code)
where any v in r.communication satisfies
   any c in v.language.coding satisfies c.code = 'en-US'
   end
end;

#5

Wow ! Problem Solved with Version: 4.6.3-4136 Enterprise Edition (build-4136) . Thank you @vsr1