尝试在 Couchbase Python SDK 的 N1QL 中构建主索引时出现 NotSupportedError

NotSupportedError when trying to build primary index in N1QL in Couchbase Python SDK

我正在尝试使用 Python 中针对 Couchbase 的新 N1QL 查询。 我在 Couchbase 4.0.0 中设置了我的数据库。

我最初的尝试是像这样检索所有文档:

from couchbase.bucket import Bucket

bucket = Bucket('couchbase://localhost/dafault')

rv = bucket.n1ql_query('CREATE PRIMARY INDEX ON default').execute()
for row in bucket.n1ql_query('SELECT * FROM default'):
    print row

但这会产生 OperationNotSupportedError:

Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 2357, in <module>
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1777, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/Users/my_user/python_tests/test_n1ql.py", line 9, in <module>
    rv = bucket.n1ql_query('CREATE PRIMARY INDEX ON default').execute()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/couchbase/n1ql.py", line 215, in execute
    for _ in self:
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/couchbase/n1ql.py", line 235, in __iter__
    self._start()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/couchbase/n1ql.py", line 180, in _start
    self._mres = self._parent._n1ql_query(self._params.encoded)
couchbase.exceptions.NotSupportedError: <RC=0x13[Operation not supported], Couldn't schedule n1ql query, C Source=(src/n1ql.c,82)>

这里是我使用的所有版本号:

Couchbase Server: 4.0.0
couchbase python library: 2.0.2
cbc: 2.5.1
python: 2.7.8
gcc: 4.2.1

有人知道这里可能出了什么问题吗?到目前为止,我找不到解决这个问题的方法。

node.js 的另一张工单也发生了同样的问题。有人提议首先为特定存储桶启用 n1ql。在 python 中也需要这个吗?

您似乎没有使用 QueryIndex 服务配置任何集群节点。因此,返回的错误表明没有可用的节点。

我在尝试创建主索引时也遇到了类似的错误。

    Create a primary index...
Traceback (most recent call last):
  File "post-upgrade-test.py", line 45, in <module>
    mgr.n1ql_index_create_primary(ignore_exists=True)
  File "/usr/local/lib/python2.7/dist-packages/couchbase/bucketmanager.py", line 428, in n1ql_index_create_primary
    '', defer=defer, primary=True, ignore_exists=ignore_exists)
  File "/usr/local/lib/python2.7/dist-packages/couchbase/bucketmanager.py", line 412, in n1ql_index_create
    return IxmgmtRequest(self._cb, 'create', info, **options).execute()
  File "/usr/local/lib/python2.7/dist-packages/couchbase/_ixmgmt.py", line 160, in execute
    return [x for x in self]
  File "/usr/local/lib/python2.7/dist-packages/couchbase/_ixmgmt.py", line 144, in __iter__
    self._start()
  File "/usr/local/lib/python2.7/dist-packages/couchbase/_ixmgmt.py", line 132, in _start
    self._cmd, index_to_rawjson(self._index), **self._options)
couchbase.exceptions.NotSupportedError: <RC=0x13[Operation not supported], Couldn't schedule ixmgmt operation, C Source=(src/ixmgmt.c,98)>

向集群添加查询和索引节点解决了问题。