0

I have the following sample documents in my couchdb. The original table in production has about 2M records.

{ 
  {
      "_id": "someid|goes|here",
      "collected": {
          "tags": ["abc", "def", "ghi"]
      }
  },
  {
      "_id": "someid1|goes|here",
      "collected": {
           "tags": ["abc", "klm","pqr"]
      },
  },
  {
      "_id": "someid2|goes|here",
      "collected": {
           "tags": ["efg", "hij","klm"]
      },
  }
}

Based on my previous question here, how to search for values when the selector is an array, I currently have an index added for the collected.tags field, but the search is still taking a long time. Here is the search query I have.

{
  "selector": {
    "collected.tags": {
      "$elemMatch": {
        "$regex": "abc"
      }
    }
  }
}

There are about 300k records matching the above condition, there search seems to take a long time. So, I want to create a indexed view to retrieve and lookup faster instead of a find/search. I am new to couchdb and am not sure how to setup the map function to create the indexed view.

Abishek
  • 11,191
  • 19
  • 72
  • 111

1 Answers1

0

Figured the map function out myself. Now all the documents are indexed and retrievals are faster

function (doc) {
  if(doc.collected.tags.indexOf('abc') > -1){
    emit(doc._id, doc);
  }
}
Abishek
  • 11,191
  • 19
  • 72
  • 111