You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2022/04/19 15:31:38 UTC

[GitHub] [couchdb] willholley commented on issue #3998: Records not getting retrieved in case of indexed array.

willholley commented on issue #3998:
URL: https://github.com/apache/couchdb/issues/3998#issuecomment-1102795535

   @shrikantgarg17 array elements are not indexed independently when using a `json` index (see https://github.com/apache/couchdb/issues/1388 for the explanation). At query time, CouchDB will ignore the `$elemMatch` operator when evaluating which indexes can be used. Given the only other clause in your selector is `_id > 0`, you end up with a full database scan. 
   
   As a solution, you can either use a [view](https://docs.couchdb.org/en/3.2.0/ddocs/views/index.html) directly and emit each element in the index as a key, or add the [search plugin](https://docs.couchdb.org/en/3.2.0/ddocs/search.html) and use the `text` type index, which can index array elements independently.
   
   The view solution would be a map function like:
   ```
   function(doc) {
       if(doc.shri && doc.shri.tags) {
           for (var i = 0; i <  doc.shri.tags.length; i++) { 
               emit(doc.shri.tags[i], null);
           }
       }
   }
   ```
   
   and then all the view using `http://couchdburl/db/_design/my_ddoc/_view?key="xyz"`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org