在 war 文件中包含 index.yaml 文件的位置

Where to include index.yaml file in a war file

我在 Google Compute Engine 上部署了一个 java Web 应用程序。我正在使用 Google Cloud Datastore 来存储数据。我正在使用 GQL 查询生成器获取数据。只要只涉及一个参数,我就可以从数据存储中检索数据。简单查询,例如:

"SELECT * FROM logintracker WHERE logdate='2017-10-25' " 

对我来说工作得很好。但是,如果我添加一些额外的参数,例如:

"SELECT * FROM logintracker WHERE logdate='2017-10-25' ORDER By logtime DESC" 

不工作。我收到回复说数据存储需要开发人员提供的索引文件。我做了一些研究,发现我需要在 index.yaml 文件中指定索引。这是我的 index.yaml 文件:

indexes:
- kind: logintracker  
  ancestor: no
  properties:
  - name: logtime
    direction: desc
  - name: logdate 

这是我的问题。我应该在我的应用程序 war 文件中的什么地方包含这个 index.yaml 文件。或者是否有任何其他位置需要我直接在服务器上上传 index.yaml 文件 - 比如在云存储中?

需要该信息的不是您的应用程序,而是数据存储本身。这就是为什么索引配置没有专门为应用程序配置,而是直接上传到 GCP(单独或与应用程序一起,取决于应用程序类型)。

如果您使用的是数据存储模拟器,则文件需要位于特定位置。来自 About index.yaml:

The index.yaml is located in the <project-directory>/WEB-INF/ folder. By default, the data directory that contains WEB-INF/appengine-generated/index.yaml is ~/.config/gcloud/emulators/datastore/. See Cloud Datastore emulator project directories for additional details.

关于将文件上传到 GCP(即更新实际数据存储索引),来自 The development workflow using the command-line tool:

The following is the typical workflow using the gcloud tool:

[...]

  1. Upload the generated indexes with the create-indexes command, passing in the path to your local index.yaml file, as in the following example:

    gcloud datastore create-indexes ~/.config/gcloud/emulators/datastore/WEB-INF/index.yaml
    

    The example path assumes you have not set a specific directory for the data-dir option. If you have set a specific directory, modify the path to use the path to your index.yaml file.

[...]

  1. Over time, you might no longer use some of the indexes. You can delete unused indexes from your production Cloud Datastore instance by removing them from your local index.yaml file and then invoking the cleanup-indexes command:

    gcloud datastore cleanup-indexes ~/.config/gcloud/emulators/datastore/WEB-INF/index.yaml
    

    If you have set a specific directory for the data-dir option, modify the path in the example to use the path to your index.yaml file.

如果您使用手动制作的 index.yaml 文件,您需要指定该文件的位置,而不是在上述引号中提到的 gcloud datastore 命令中指定 ~/.config/gcloud/emulators/datastore/WEB-INF/index.yaml