Creating filtered indexes on couchdb

1.2k views Asked by At

I've been trying to create a filtered index as per CouchDB 2.1 documentation, but failed miserably (at the bottom of the section there's an example for "index creation using all available query parameters").

Basically, I have a bunch of documents that have different class attribute on them (just like a document type). I am trying to create an index only for documents with class="File" and extension="pdf"

{
  "index": {
    "fields": [
      "_id", "class", "extension"
    ],
    "selector": {
      "class": {
        "$eq": "File"
      },
      "extension": {
        "$eq": "pdf"
      }
    }
  },
  "type": "json"
}

However, when I attempt to create an index from Futon, i get the Invalid key selector for this request error. Am I interpreting documentation wrong or was it something I missed?

1

There are 1 answers

7
IanC On

I can't see anything in the documentation that says you can have a selector within the index. The documentation suggests your "Post" to create the index can have these query parameters: index, ddoc, name and type. The index parameter is supposed to only have an array of field names (and optionally a sort order).

I have not tried this (I have an older version of CouchDb at the moment), but I would remove any other parameters than these before trying to create the index again.

I wonder if the example you mention is a bug in the documentation? I am not sure if it really belongs in the section on index creation.