问题
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;
}
}
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
Server Node Screenshots
回答1:
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;"
回答2:
For me bucket name with '-' doesnt work while creating index. So beer-sample doesnt work but beer_sample works.
来源:https://stackoverflow.com/questions/37109050/unable-to-create-primary-index-for-couchbase-bucket-on-ubuntu-14-04