简体   繁体   English

在Google App Engine for Search API中创建索引的时间/位置-Java

[英]When/Where to create index in Google App Engine for Search API - Java

I'm creating a Java web server on the Google App Engine to do full text search on my database. 我正在Google App Engine上创建Java Web服务器,以对数据库进行全文搜索。 Before I can search, I have to add all my database entries to an index. 在搜索之前,我必须将所有数据库条目添加到索引中。 I should only have to do this once because the index is stored in persistent storage. 我只需要这样做一次,因为索引存储在持久性存储中。 Even if GCP creates a new instance of my Java server, the index should still be there. 即使GCP创建了Java服务器的新实例,索引也应该仍然存在。

My question is, how do I set up my program so it will only create the index once? 我的问题是,如何设置程序,使其仅创建索引一次? I've tried using Warming Services, but as I understand it that will be called every time a new instance is created, so there'd be redundant calls to my index creation code 我曾尝试使用Warming Services,但据我了解,每次创建新实例时都会调用它,因此对索引创建代码会有多余的调用

You could totally decouple the search API index updates from the instance lifetime cycle by specifically tracking the index updates for each of the respective database (or datastore) entries. 通过专门跟踪每个相应数据库(或数据存储)条目的索引更新,您可以完全将Search API索引更新与实例生存期脱钩。

Basically you'd only need to add a boolean property indicating if the entity was indexed (from the search API perspective, of course) or not. 基本上,您只需要添加一个布尔属性即可指示是否为该实体建立了索引(当然,从搜索API的角度来看)。 Then you'd only need to update the index with the entries for which the property is not set, which you can do at instance warm-up/startup or via periodic cron jobs, depending on your app needs. 然后,您只需要使用未设置该属性的条目来更新索引,就可以根据应用程序的需要在实例热身/启动时或通过定期的cron作业进行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM