问题描述
我正在尝试使用laravel 4.2从懒人桶中获取数据.并面临与PRIMARY INDEX相关的问题.以下是详细信息.有人可以建议我做错了什么吗?谢谢.
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.
控制器:
<?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;
}
}
获取以下错误消息:
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.
控制器(已更新):
<?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)
似乎两个错误都与(PRIMARY)键有关.因此,我尝试从控制器和./cbq创建主键.但是案件失败了.以下是详细信息.
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;
}
}
页面抛出以下错误:
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};)
来自./cbq的查询也引发了类似的错误.
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
}
}
请帮助我了解如何为长椅式水桶创建PRIMARY KEY.让我知道是否需要更多信息.
Please help me on how to create PRIMARY KEY for couchbase buckets. Let me know if more information is required.
编辑
服务器节点屏幕截图
推荐答案
我不确定这是否是正确的方法,但是在将查询更改为以下内容后,问题得以解决,并且能够执行CRUD操作.
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代替GSI; "
这篇关于无法为Couchbase桶创建CREATE PRIMARY INDEX.在UBUNTU 14.04上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!