使用_find查询和use_index遇到麻烦 [英] Trouble using _find query with use_index

查看:144
本文介绍了使用_find查询和use_index遇到麻烦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在CouchDB 2.x中使用类似于MongoDB的 _find 查询:

http://docs.couchdb.org/en/2.1.0/api/database/find.html

I am trying to use the MongoDB-like _find query in CouchDB 2.x:
http://docs.couchdb.org/en/2.1.0/api/database/find.html

使用以下命令,我得到一个警告,我应该使用索引。

With the following, I get a warning that I should be using an index.

curl -k -X POST "$COUCHDB_HOST/vacation-at-ibm/_find" \
>      -H "Content-Type: application/json" \
>      -w "\nhttp_code=%{http_code}\n" \
>      --data-binary '
> {
>     "selector": {
>         "ownerId": {"$eq": "1A4061897"}
>     }
> }
> '

{"warning":"no matching index found, create an index to optimize query time",

"docs":[
{...}
http_code=200

但是当我添加 use_index 选项,出现一个错误,它找不到我的索引:

But when I add the use_index option, I get an error that it can't find my index:

curl -k -X POST "$COUCHDB_HOST/vacation-at-ibm/_find" \
>      -H "Content-Type: application/json" \
>      -w "\nhttp_code=%{http_code}\n" \
>      --data-binary '
> {
>     "use_index": [
>         "_design/EventDocument",
>         "events-by-ownerId"
>     ],
>     "selector": {
>         "ownerId": {"$eq": "1A4061897"}
>     }
> }
> '
{"error":"unknown_error","reason":"Unknown Error: mango_idx :: {no_usable_index,no_index_matching_name}"}

我假设我应该指定设计文档关键字和视图名称。但这是一个猜测,因为我发现 use_index 选项绝对没有有用的文档。没有实际尝试使用它的示例。这是我的设计文档:

I'm making the assumption that I should be specifying the design document key, and the view name. But that's a guess, because I have found absolutely no useful documentation for the use_index option. There are no examples of actually trying to use it. Here's my design document:

{
  "_id": "_design/EventDocument",
  "_rev": "1-115570169dec7d32845c3b7c6e6978fe",
  "language": "javascript",
  "views": {
    "events-by-ownerId": {
      "map": "function(doc) { if (doc.docType == 'event' && doc.ownerId) { var firstDate = null;  if (doc.date) { firstDate = doc.date;  }  emit([doc.ownerId, firstDate], doc); }}"
    }
  }
}

有人知道如何使用此选项吗?我为设计文档和索引使用了错误的值吗?

Does anybody know how to use this option? Am I using the wrong values for the design doc and the index?

推荐答案

所以当他们说索引 ,它们引用了 / db / _index 端点。

So when they say, "Create an index", they refer to the /db/_index endpoint.

您需要通过此过程创建索引。您可以指定要存储索引的位置,否则CouchDB将创建一个设计文档并将索引存储在其中。

You need to create an index through this process. You can specify where you want to store the index, otherwise, CouchDB will create a design document and store the index in there.

这篇关于使用_find查询和use_index遇到麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆