1

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?

AVK
  • 645
  • 9
  • 22

1 Answers1

0

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.

IanC
  • 865
  • 8
  • 11
  • it says that "index is (json) – JSON object describing the index to create", which can be an arbitrary description object. Also if you scroll down to the part where it says "Example index creation using all available query parameters", below you will see what seems to be an extended index definition, which includes a `selector`. Am i wrong? – AVK Sep 06 '17 at 21:15
  • I am not sure, but the error message your are getting suggests the "selector" key is the problem. Using map/reduce might allow you to create the index you want. It is a little more long-winded but might be simpler for creating an advanced index. You would just need a function that "emits" the index entries (key and value pairs) you want based on whatever criteria you like. – IanC Sep 07 '17 at 07:15
  • Nope, no map-reduces. Im talking about indexes only – AVK Sep 07 '17 at 11:31
  • Perhaps we are talking at cross-purposes, but you can create an index in CouchDb by putting a map function in the view object within a design document. There is some documentation on this here: http://guide.couchdb.org/draft/design.html#basic – IanC Sep 08 '17 at 10:15
  • are you saying that common design documents can be used to create indexes for Mango queries? – AVK Sep 08 '17 at 14:09
  • The answer is not as easy as yes or no. There is a discussion of it here that goes into the details of Mango and map/reduce by people more knowledgeable than me: https://stackoverflow.com/questions/40753347/couchdb-mango-performance-vs-map-reduce-views – IanC Sep 11 '17 at 09:02
  • In this case indexes are not the same as design docs then. I've been using Couch 1.6 for a couple of years before. That's why I was a bit surprised, bacause in Fauxton indexes are located differently from design docs – AVK Sep 11 '17 at 16:11