使用$或selector,此选择器没有可用的索引

时间:2016-04-25 14:54:23

标签: indexing couchdb cloudant couchdb-mango

我想要检索

  • _id 1

    的文档

  • 包含value === 13anotherValue === 56
  • 的文档

错误:

  

此选择器没有可用的索引。

这是我的疑问:

{
  "selector": {
      "$or": [
          {
              "_id": "1"
          },
          {
              "value": "13",
              "anotherValue": "56"
          }
       ]
   }
}

索引设置:

Your available Indexes:
special: _id
json: value, anotherValue
json: _id, value, anotherValue

1 个答案:

答案 0 :(得分:3)

对于此查询,您需要添加一个选择器以获取所有ID,如下所示:

{
    "selector": {
        "_id": {"$gt":null},
        "$or": [
            {
                "_id": "1"
            },
            {
                "value": "13",
                "anotherValue": "56"
            }
        ]
    }
}

您可以在此处了解更多信息:

https://cloudant.com/blog/mango-json-vs-text-indexes/

这个SO帖子:

index and query items in an array with mango query for cloudant and couchdb 2.0

或者,您可以在所有字段上添加文本索引:

{
    "index": {},
    "type": "text"
}

然后你的原始选择器应该可以工作。