【问题标题】:Google App Engine: The API package 'search' or call 'IndexDocument()' was not foundGoogle App Engine:未找到 API 包“搜索”或调用“IndexDocument()”
【发布时间】:2016-07-17 11:24:23
【问题描述】:

使用 Google App Engine 的搜索 API,我正在尝试将一些文档索引到测试索引中。我正在使用 Google App Engine 官方文档中给出的代码示例。 但是当我尝试运行下面的 sn-p 时。当我通过index.put 放置文档时出现以下错误:

线程“主”com.google.apphosting.api.ApiProxy$CallNotFoundException 中的异常:未找到 API 包“搜索”或调用“IndexDocument()”。 在 com.google.apphosting.api.ApiProxy$1.get(ApiProxy.java:179) 在 com.google.apphosting.api.ApiProxy$1.get(ApiProxy.java:177) 在 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) 在 test.service.SearchingService.indexADocument(SearchingService.java:52)

这里是sn-p的代码:

 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 Kepler 一起使用。我是在本地开发服务器上运行代码还是在 apppot 上托管的生产环境中运行代码都没有关系。我犯了同样的错误。 我已经在 Eclipse 中通过我的谷歌帐户进行身份验证,并且能够通过 Eclipse 将我的代码推送到生产环境中。有没有人见过这个错误?

【问题讨论】:

  • 你在用线程做事吗?如果此代码未在接收 HTTP 请求的线程上执行,则可能会发生这种情况。
  • @emcmanus 不,我只是使用示例代码来测试索引如何在单个线程中工作。我没有找到使索引工作所需的任何特定配置,所以只是尝试执行上面的代码。

标签: java eclipse google-app-engine gae-search


【解决方案1】:

因此,在尝试调用搜索 API 时需要注意的事项很少。我的设置中的第一个错误是我使用的是旧版本的 GAE SDK (1.9.18)。

修复该问题后,我在尝试索引文档时仍然遇到错误。我从 appengine 上下文调用了搜索查询函数,但我的索引导致了同样的错误,因为它是从“主”函数运行的。应始终在 appengine 上下文中运行 Search API 的所有功能。

【讨论】:

    猜你喜欢
    • 2014-07-14
    • 2017-01-15
    • 1970-01-01
    • 1970-01-01
    • 2014-11-18
    • 1970-01-01
    • 1970-01-01
    • 2016-11-30
    • 1970-01-01
    相关资源
    最近更新 更多