使用谷歌應用程序引擎的搜索API,我試圖索引某些文檔轉換爲測試指標。我正在使用Google App Engine官方文檔中給出的代碼示例。 但是,當我嘗試運行下面的代碼片段。我收到以下錯誤,當我通過TR向index.put
把一個文件:谷歌應用程序引擎:該API包「搜索」或稱之爲「IndexDocument()」未找到
異常線程「main」 com.google.apphosting.api.ApiProxy $ CallNotFoundException:該API包「搜索」或稱之爲「IndexDocument( )' 沒找到。 at com.google.apphosting.api.ApiProxy $ 1.get(ApiProxy.java:179) at com.google.apphosting.api.ApiProxy $ 1.get(ApiProxy.java:177) at com.google.appengine。 api.utils.FutureWrapper.get(FutureWrapper.java:88) 在com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:88) 在com.google.appengine.api.search.FutureHelper。 getInternal(FutureHelper.java:73) 在com.google.appengine.api.search.FutureHelper.quietGet(FutureHelper.java:32) 在com.google.appengine.api.search.IndexImpl.put(IndexImpl.java: 486) at test.service.SearchingService.indexADocument(SearchingService.java:52)
下面的代碼片段:
IndexSpec indexSpec = IndexSpec.newBuilder().setName(indexName).build();
SearchService service = SearchServiceFactory.getSearchService(
SearchServiceConfig.newBuilder().setDeadline(10.0).setNamespace("geeky").build());
Index index = service.getIndex(indexSpec);
final int maxRetry = 3;
int attempts = 0;
int delay = 2;
while (true) {
try {
index.put(document); // ERROR!!!!!!!!!!
} catch (PutException e) {
if (StatusCode.TRANSIENT_ERROR.equals(e.getOperationResult().getCode())
&& ++attempts < maxRetry) { // retrying
Thread.sleep(delay * 1000);
delay *= 2; // easy exponential backoff
continue;
} else {
throw e; // otherwise throw
}
}
break;
}
}
我使用AppEngine上的Java-SDK-1.9.18與Eclipse開普勒。如果我在本地開發服務器上運行代碼或在appspot上託管的生產環境中,則無關緊要。我犯了同樣的錯誤。 我已經在eclipse中對我的Google帳戶進行了身份驗證,並且能夠通過eclipse將我的代碼投入生產。有沒有人看到過這個錯誤?
你在做什麼與線程?如果此代碼未在接收到HTTP請求的線程上執行,則可能會發生這種情況。 – emcmanus
@emcmanus不,我只是使用示例代碼來測試索引在單個線程中的工作方式。我沒有找到任何需要進行索引編制的特定配置,因此只是嘗試執行上面的代碼。 –