【问题标题】:How to enable primary index for a bucket in couchbase using python SDK?如何使用 python SDK 为 couchbase 中的存储桶启用主索引?
【发布时间】:2017-07-21 15:34:41
【问题描述】:

我是 couchbase 的新手,正在尝试查询现有存储桶中的文档。当我在python中执行我的服务器代码时,报告了以下错误日志

HTTPError: <RC=0x3B[HTTP Operation failed. Inspect status code for details], HTTP Request failed. Examine 'objextra' for full result, Results=1, C Source=(src/http.c,140), OBJ=ViewResult<rc=0x3B[HTTP Operation failed. Inspect status code for details], value={u'status': u'fatal', u'metrics': {u'elapsedTime': u'64.108808ms', u'executionTime': u'63.940999ms', u'resultSize': 0, u'resultCount': 0, u'errorCount': 1}, u'errors': [{u'msg': u'No primary index on keyspace default. Use CREATE PRIMARY INDEX to create one.', u'code': 4000}], u'requestID': u'14a2ba49-512b-4a4b-9e8d-37ef6c010c34'}, http_status=404>>

我当前执行get请求/查询操作的python sn-p是

 def get(self):
        tableName = request.args.get("tablename")

        createPrimaryIndex = N1QLQuery("create primary index on `default`")
        cb.n1ql_query(createPrimaryIndex)

        q = N1QLQuery("select * from `default` where tablename='{0}' limit 10;".format(tablename))
        for row in cb.n1ql_query(q):
            print row

我观察到,如果我进入 couchbase 控制台并执行查询 set primary index on default(而不是在我的服务器代码中执行它),然后执行我的服务器代码,则数据返回正常。但是,我希望在我的服务器代码中执行此查询。这可能吗?如果可以,我应该怎么做?

【问题讨论】:

    标签: python couchbase


    【解决方案1】:

    您可以使用n1ql_index_createdefer 设置为False(这是默认值),或者将其设置为True 并使用build_deferred_indexes/watch_indexes 的组合来检测索引的时刻已创建。

    https://github.com/couchbase/couchbase-python-client/blob/2.2.5/couchbase/bucketmanager.py#L355

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-04
      • 1970-01-01
      • 2014-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多