0

I am trying to sort a list of items by my property 'price' but I'm getting error.

This is my filter

items = ofy().load().type(MyItem.class)
            .filter("OtherEntityRef", tmpEntity)
            .order("price").limit(100)
            .list();

But we I run it, the log shows the erro:

 Uncaught exception from servlet 
java.io.IOException: com.google.appengine.repackaged.org.codehaus.jackson.map.JsonMappingException: no matching index found.
The suggested index for this query is:
    <datastore-index kind="MyClass" ancestor="false" source="manual">
        <property name="OtherEntityRef" direction="asc"/>
        <property name="price" direction="asc"/>
    </datastore-index>

 (through reference chain: java.util.HashMap["items"])
    at com.google.api.server.spi.response.ServletResponseResultWriter.writeValueAsString(ServletResponseResultWriter.java:187)
    at com.google.api.server.spi.response.ServletResponseResultWriter.write(ServletResponseResultWriter.java:74)
    at com.google.api.server.spi.SystemService.invokeServiceMethod(SystemService.java:394)
    at com.google.api.server.spi.SystemServiceServlet.execute(SystemServiceServlet.java:160)
    at com.google.api.server.spi.SystemServiceServlet.doPost(SystemServiceServlet.java:118)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.googlecode.objectify.ObjectifyFilter.doFilter(ObjectifyFilter.java:48)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:125)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:37)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.JdbcMySqlConnectionCleanupFilter.doFilter(JdbcMySqlConnectionCleanupFilter.java:60)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:260)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
    at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:78)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:148)
    at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:468)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:437)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:444)
    at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:256)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:308)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:300)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:441)
    at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:235)
    at java.lang.Thread.run(Thread.java:745)

I have defined the price as @Index, so it should be indexed.

@Index
 double price;

Do someone knows what it could be?

Dan McGrath
  • 41,220
  • 11
  • 99
  • 130
jluiz20
  • 199
  • 1
  • 2
  • 12
  • Is this on the dev server or in production? – Dan Cornilescu Jan 28 '16 at 22:22
  • It is in the server. I got it from the Google Cloud Logging. – jluiz20 Jan 28 '16 at 22:27
  • Sorry, still unclear (my question wasn't clear either): are these logs from the app running on your development server or from the app deployed on GAE? :) (it appears the Cloud Logging API can run on the development server as well). – Dan Cornilescu Jan 28 '16 at 22:35
  • Sorry for the unclear answer(I'm fairly new to GAE). It's running on the GAE. If I deploy a version with the `.order("price").limit(100)` it gives me this error. If I comment it out. It works perfectly. – jluiz20 Jan 28 '16 at 22:43
  • 1
    In the Developer Console goto Datastore -> Indexes. Do you see in there the suggested index from the error message? If no then the index was not deployed properly. If yes check its status - depending on the size of you data it may take a while for the index to be built after deployment, you'll see this error until the build completes and the status becomes `Serving`. – Dan Cornilescu Jan 28 '16 at 22:50
  • 1
    Also check this Q&A (from python, you need to adapt to java): http://stackoverflow.com/questions/16137960/how-to-fix-index-error-when-querying-gae-datastore – Dan Cornilescu Jan 28 '16 at 23:02
  • Now I get it write. The Indexes was empty. I did not know about the composite Indexes, I knew only the buit-in. I added the datastore-indexes.xml and put my index configuration and it worked. Now it has a index and it is showing in the Indexes page as Serving. Thank you very much Dan Cornilescu! You really helped me – jluiz20 Jan 29 '16 at 00:30
  • 1
    Please add an answer documenting the solution to not leave the question hanging unanswered. Thx. – Dan Cornilescu Jan 29 '16 at 00:34

1 Answers1

1

After the help of @Dan Cornilescu I found the problem.

I had not had any composite Indexes. My Datastore -> Indexes was empty. To solve it I created a XML file under the WEB-INF folder called datastore-indexes.xml and there I explicitly defined my index.

<?xml version="1.0" encoding="utf-8"?>
<datastore-indexes
    autoGenerate="true">
    <datastore-index kind="MyEntity" ancestor="false" source="manual">
        <property name="OtherEntityRef" direction="asc"/>
        <property name="price" direction="asc"/>
    </datastore-index>
   </datastore-indexes>

As I understood was that if you use order if you have to add your own index. The built-in does not work in this case.(Here I am expressing my basic knowledge).

Thank you @Dan Cornilescu for the time you take to help.

jluiz20
  • 199
  • 1
  • 2
  • 12
  • Only adding datastore-indexes.xml has solved the problem? I'm getting the same error without the part of "The suggested index for this query is..." – adlagar Jun 13 '18 at 15:50