Pythonで作成したプログラムをGoogleAppEngine(GAE)で動作させる際、『NeedIndexError: no matching index found.The suggested index for this query is:』というエラーが出る場合があります。
エラーの原因と対処法は以下から。
GAEにおいて、簡単なクエリ処理用のインデックスは自動生成されますが、複雑なクエリ処理用のインデックスは『index.yaml』に記述して定義する必要がある様です。
よって、『NeedIndexError: no matching index found.The suggested index for this query is:』というエラーの後に書かれている内容を『index.yaml』に記述する必要があります。
indexes: # AUTOGENERATED # This index.yaml is automatically updated whenever the dev_appserver # detects that a new type of query is run. If you want to manage the # index.yaml file manually, remove the above marker line (the line # saying "# AUTOGENERATED"). If you want to manage some indexes # manually, move them above the marker line. The index.yaml file is # automatically uploaded to the admin console when you next deploy # your application using appcfg.py. - kind: Sample properties: - name: hoge - name: moge - name: fuga
本エラーはWeb上にデプロイした環境で発生しますが、ローカル環境では発生せず、また時間を置いてWeb上で確認するとエラーが出ない場合があり、問題の原因を特定するのが困難な問題です。
これは『ローカル環境のindex.yamlは自動で上書き更新されるがWeb上のindex.yamlは上書き更新されない』のが原因です。
この様な状態になるとエラー原因の特定が困難になります。