dongxixia6399
dongxixia6399
2016-05-09 06:27

无法为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 douhuiyan2772 5年前

    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;"

    点赞 评论 复制链接分享
  • douhao5280 douhao5280 5年前

    For me bucket name with '-' doesnt work while creating index. So beer-sample doesnt work but beer_sample works.

    点赞 评论 复制链接分享

相关推荐