title: Couchbase Array indexing
body: <p>Couchbase version 5.0</p>
  
  <p>I'm trying to speedup the query below by array indexing, and I cannot get it right.</p>
  
  <pre><code>SELECT DISTINCT document_data.* FROM `optima` AS optima 
  UNNEST optima.documents AS document_data 
  UNNEST document_data.attachments AS attachment_data 
  WHERE optima.type = "accountDocument"
  AND attachment_data.objectId IN ["18485,0"] 
  AND attachment_data.objectType IN ["account","service","cart","order"];
  </code></pre>
  
  <p>I have created the following indexes, but array index on attachments element does not seem to work</p>
  
  <pre><code>CREATE PRIMARY INDEX `optima-primary-index` ON `optima` USING GSI;
  
  CREATE INDEX idx_document_nested ON `optima`
  (DISTINCT ARRAY document_data FOR document_data IN optima.documents END) 
  WHERE type = "accountDocument";
  
  CREATE INDEX idx_attachment_nested ON `optima`
      (DISTINCT ARRAY 
  (DISTINCT ARRAY attachment_data FOR attachment_data IN document_data.attachments END) 
      FOR document_data IN optima.documents END) 
  WHERE type = "accountDocument";
  
  CREATE INDEX `idx_type` ON `optima`(`type`);
  </code></pre>
  
  <p>Any suggestions?</p>