dongxixia6399 2016-05-09 06:27
浏览 126
已采纳

无法为couchbase存储桶创建PRIMARY INDEX。 在UBUNTU 14.04

I am trying to get data from couchbase bucket using laravel 4.2 . And facing issue related to PRIMARY INDEX. Below are the details. Can someone please suggest where I am doing wrong. Thanks.

Controller:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use CouchbaseCluster;

class HomeController extends Controller {

    public function index() {


//        phpinfo();die;

//        
    $Cluster  =  New  CouchbaseCluster ( 'http://127.0.0.1:8091' ); 
    $Bucket = $Cluster->OpenBucket('beer-sample');

// Retrieve a document

    Try {
        $Result = $Bucket->Get('21St_amendment_brewery_cafe');
    } Catch (Exception $E) {
        Echo "CouchbaseException:" . $E->getMessage() . " \ N ";
    }
    $doc = Json_decode($Result->Value, True);
    var_dump($doc);die;
    }

}

getting below error message:

CouchbaseException in CouchbaseBucket.class.php line 196:
The key does not exist on the server

Then I changed my controller code and ran it again.

Controller(Updated):

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use CouchbaseCluster;

class HomeController extends Controller {

    public function index() {


//        phpinfo();die;
        $query = 'SELECT * FROM `beer-sample` limit 2';
        $res = \DB::connection()->bucket('beer-sample')->select($query);
        var_dump($res);die;

    }

}
Then I am getting this error.

QueryException in Connection.php line 673:
No primary index on keyspace beer-sample. Use CREATE PRIMARY INDEX to create one. (SQL: SELECT * FROM `beer-sample` limit 2)

It seems both errors are related to (PRIMARY) Key. So, I tried to create primary key from my controller and ./cbq . But cases are failing. Below are the details.

Controller logic to create PRIMARY KEY:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use CouchbaseCluster;

class HomeController extends Controller {

    public function index() {


//        phpinfo();die;
        $query = 'CREATE PRIMARY INDEX `beer-sample-primary-index` ON `beer-sample` USING GSI WITH {"defer_build":true};';
        $res = \DB::connection()->bucket('beer-sample')->select($query);
        var_dump($res);die;      
  }

}

Page is throwing below error:

QueryException in Connection.php line 673:
GSI CreatePrimaryIndex() - cause: Fails to create index. There is no available index service that can process this request at this time. Index Service can be in bootstrap, recovery, or non-reachable. Please retry the operation at a later time. (SQL: CREATE PRIMARY INDEX `beer-sample-primary-index` ON `beer-sample` USING GSI WITH {"defer_build":true};)

Query from ./cbq also thrown similar error.

srturaka@srturaka-pc:/opt/couchbase/bin$ ./cbq
Couchbase query shell connected to http://localhost:8093/ . Type Ctrl-D to exit.
cbq> CREATE PRIMARY INDEX ON `beer-sample` USING GSI;
{
    "requestID": "30239420-7dc2-4892-ba90-1ecf0474ba19",
    "signature": null,
    "results": [
    ],
    "errors": [
        {
            "code": 5000,
            "msg": "GSI CreatePrimaryIndex() - cause: Fails to create index.  There is no available index service that can process this request at this time. Index Service can be in bootstrap, recovery, or non-reachable. Please retry the operation at a later time."
        }
    ],
    "status": "errors",
    "metrics": {
        "elapsedTime": "10.005267815s",
        "executionTime": "10.005169082s",
        "resultCount": 0,
        "resultSize": 0,
        "errorCount": 1
    }
}

Please help me on how to create PRIMARY KEY for couchbase buckets. Let me know if more information is required.

EDIT

enter image description here

Server Node Screenshots

enter image description here

enter image description here

enter image description here

</div>
  • 写回答

2条回答 默认 最新

  • douhuiyan2772 2016-05-10 06:39
    关注

    I am not sure if this is a proper way, but my issue got resolved after I changed my query to below.And I am able to perform CRUD operations.

    $query = 'CREATE PRIMARY INDEX beer-sample-primary-index ON beer-sample USING View';

    "VIEW instead of GSI;"

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥30 用arduino开发esp32控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿