0
返回的錯誤是500當正在運行的應用程序處理ViewDogs的獲取請求時發生內部服務器錯誤。在GAE堆棧驅動控制檯我得到:GAE NeedIndexError:
NeedIndexError: no matching index found - recommended index is:
- kind:Dog
ancestor: yes
properties: -
name: id
direction: desc".
我確認有加載一個名爲狗的指數,它目前顯示「服務」
也確認有4只狗成功創建,它們可以被查詢DataStore實體選項卡單獨並使用SELECT * FROM Dog。還要注意註釋掉的行self.response.write('You dog!')
,如果沒有註釋,它會按預期返回,所以大概不是路由問題。我可以通過GET返回一條狗(這段代碼被省略)類ViewAllDogs中的代碼可能有問題,在GAE文檔中盡我所能。
index.yaml中的文件,我確認上傳,並具有狀態: 「服務」
indexes:
- kind: Dog
ancestor: yes
properties:- name: id
direction: desc
- name: name
direction: desc
- name: type
direction: desc
- name: weight
direction: desc
- name: boarded
direction: desc
app.yaml文件:
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: main.app
main.py
import webapp2
from datetime import datetime
from google.appengine.ext import ndb
import webbrowser
import json
def gql_json_parser(query_obj):
result = []
for entry in query_obj:
result.append(dict([(p, unicode(getattr(entry, p))) for p in entry.properties()]))
return result
class Dog(ndb.Model):
""" Models an individual Dog """
id = ndb.StringProperty(required = True, indexed = True)
name = ndb.StringProperty(required = True, indexed = True)
type = ndb.StringProperty(required = True, indexed = True)
weight = ndb.IntegerProperty(required = True, indexed = True)
boarded = ndb.BooleanProperty(required = True, indexed = True)
@classmethod
def query_dog(cls, ancestor_key):
return cls.query(ancestor=ancestor_key).order(-cls.id)
class ViewAllDogs(webapp2.RequestHandler):
def get(self):
# self.response.write('You dog!')
parent_dog = self.request.get('parent_dog')
ancestor_key = ndb.Key("Dog", parent_dog or '*noDogs*')
query_data = Dog.query_dog(ancestor_key).fetch(10)
json_query_data = gql_json_parser(query_data)
self.response.headers['Content-Type'] = 'application/json'
self.response.write(json.dumps(json_query_data))
app = webapp2.WSGIApplication([
('/ViewDogs', ViewAllDogs)
], debug=True)
類似的問題比比皆是,包括這Query google app engine datastore for all entities但沒有解決我的問題。謝謝。
通知丟失索引是已定義的指標不同。您需要的索引必須完全符合要求。 –
幾分鐘後你又試過了嗎?在對查詢或數據結構進行更改時,數據存儲索引在部署後需要幾分鐘才能更新(可能有幾個取決於數據大小)。在生產環境中,您可能希望使用'--no-promote'標誌,等待索引更新,然後將流量導向部署的新版本。 –