2013-07-02 22 views
5

**更新**谷歌雲存儲runQuery返回412「沒有匹配的索引中找到」

感謝艾爾弗雷德·福勒的指出,我需要創建這個查詢手動索引。

不幸的是,從.NET應用程序使用JSON API,似乎沒有官方支持的方式。事實上,從App Engine以外的應用程序看來,這似乎沒有辦法做到這一點,這很奇怪,因爲Cloud Datastore API旨在允許訪問App Engine之外的數據存儲區。

我能找到的最接近的黑客是POST the index definition using RPChttp://appengine.google.com/api/datastore/index/add。有人可以給我原始的規範,如何準確地做到這一點(即URL參數,身體應該看起來像什麼等),也許使用Fiddler來檢查appcfg.cmd所做的調用?

**原來的問題**

按照docs「的查詢可以在單個屬性結合平等(EQUAL)濾波器用於不同的屬性,與一個或多個不等式過濾器沿」。

然而,此查詢失敗:

{ 
"query": { 
    "kinds": [ 
    { 
    "name": "CodeProse.Pogo.Tests.TestPerson" 
    } 
    ], 
    "filter": { 
    "compositeFilter": { 
    "operator": "and", 
    "filters": [ 
    { 
     "propertyFilter": { 
     "operator": "equal", 
     "property": { 
     "name": "DepartmentCode" 
     }, 
     "value": { 
     "integerValue": "123" 
     } 
     } 
    }, 
    { 
     "propertyFilter": { 
     "operator": "greaterThan", 
     "property": { 
     "name": "HourlyRate" 
     }, 
     "value": { 
     "doubleValue": 50 
     } 
     } 
    }, 
    { 
     "propertyFilter": { 
     "operator": "lessThan", 
     "property": { 
     "name": "HourlyRate" 
     }, 
     "value": { 
     "doubleValue": 100 
     } 
     } 
    } 
    ] 
    } 
    } 
} 
} 

與以下響應:

{ 
"error": { 
    "errors": [ 
    { 
    "domain": "global", 
    "reason": "FAILED_PRECONDITION", 
    "message": "no matching index found.", 
    "locationType": "header", 
    "location": "If-Match" 
    } 
    ], 
    "code": 412, 
    "message": "no matching index found." 
} 
} 

回答

2

錯誤 「不匹配索引找到」。表示需要添加索引才能使查詢生效。請參閱auto index generation documentation

在這種情況下,您需要一個具有屬性DepartmentCode和HourlyRate的索引(按該順序)。

+0

感謝阿爾弗雷德!看到我對這個問題的更新。不幸的是,我使用的是JSON API,並沒有使用App Engine SDK(這將允許我輕鬆包含索引def文件)。 –

6

的JSON API尚不支持本地索引一代,但我們已經證明,你可以按照在https://developers.google.com/datastore/docs/tools/indexconfig#Datastore_Manual_index_configuration

生成索引的XML定義請給這個一杆,讓我們知道,如果一個進程它不起作用。

這是一個臨時解決方案,我們希望儘快替換自動本地索引生成。

+0

Max - 謝謝,我看到了。生成XML索引定義文件沒有問題。問題是 - 我如何將它上傳到服務器?我沒有Java或Python App Engine應用程序... –

+0

另外,該文檔的下一部分引用了一個GCD命令行工具,它看起來像我可以用來更新服務器上的索引。我在哪裏可以找到該工具? –

+0

@ codeprose-sam參閱https://developers.google.com/datastore/docs/tools/indexconfig#Updating_Indexes關於如何運行gcd來更新索引。你可以從這裏下載:https://developers.google.com/datastore/docs/downloads#tools – proppy

1

對於gcloud-node我與3條鏈路上的固定它:

和最重要的環節:

正如在上一個鏈接中所解釋的,索引是允許通過將查詢的結果集存儲在索引中來使複雜查詢運行更快的原因。當你得到no matching index found這意味着你試圖運行一個涉及orderfilter的複雜查詢。因此,爲了使您的查詢工作,您需要通過手動創建配置文件來創建索引,以便定義代表您正在嘗試運行的查詢的索引。這裏是你如何解決:

  1. 通過以下對蟒蛇的conf文件中的指令創建index.yaml文件在您的應用程序目錄下名爲例如indexes文件夾中:https://cloud.google.com/appengine/docs/python/config/indexconfig#Python_About_index_yamlhttps://github.com/GoogleCloudPlatform/gcloud-node/blob/master/system-test/data/index.yaml
  2. gcloud-node測試中得到的啓示使用此命令從配置文件創建索引: gcloud preview datastore create-indexes indexes/index.yaml 參見https://cloud.google.com/sdk/gcloud/reference/preview/datastore/create-indexes
  3. 等待索引在Cloud Datastore/Indexes中的開發人員控制檯上提供,界面應該在索引建立後顯示「正在服務」
  4. 一旦服務您的查詢應該工作

例如,對於這個查詢:

var q = ds.createQuery('project') 
    .filter('tags =', category) 
    .order('-date'); 

index.yaml樣子:

indexes: 

- kind: project 
    ancestor: no 
    properties: 
    - name: tags 
    - name: date 
    direction: desc 
相關問題