0

Using Google App Engine's Search API, I am trying to index some document into a test index. I am using the code sample given on the Google App Engine official documentation. But when I try to run the snippet below. I get the following error when I tr to put a document via index.put:

Exception in thread "main" com.google.apphosting.api.ApiProxy$CallNotFoundException: The API package 'search' or call 'IndexDocument()' was not found. 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) at com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:88) at com.google.appengine.api.search.FutureHelper.getInternal(FutureHelper.java:73) at com.google.appengine.api.search.FutureHelper.quietGet(FutureHelper.java:32) at com.google.appengine.api.search.IndexImpl.put(IndexImpl.java:486) at test.service.SearchingService.indexADocument(SearchingService.java:52)

Here's the code snippet:

 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;
          }

        }

I am using appengine-java-sdk-1.9.18 with Eclipse Kepler. It doesn't matter if I run the code on a local dev server or in production hosted on appspot. I get the same error. I am already authenticated in eclipse to my google account, and am able to push my code into production via eclipse. Has anybody seen this error before?

apurva.nandan
  • 1,061
  • 1
  • 11
  • 19
  • Are you doing anything with threads? This could happen if this code is not executing on the thread that received the HTTP request. – emcmanus Jul 18 '16 at 22:54
  • @emcmanus No, I am just using the sample code for testing how the indexing works in a single thread. I didn't find any particular configuration that was needed to make the indexing work, so just tried executing the above code. – apurva.nandan Jul 20 '16 at 06:41

1 Answers1

0

So there are few things to take care of when trying to call the Search API. The first error in my setup was that I was using an older version of GAE SDK (1.9.18).

After fixing that, I still had errors when trying to index the documents. I had the search query function called from the appengine context but my indexing caused the same error because it ran from a 'main' function. One should always run all the functions of the Search API from within the appengine context.

apurva.nandan
  • 1,061
  • 1
  • 11
  • 19