Skip to content
Advertisement

Objectify with Firestore native – no matching index found

I have a collection of very simple Java objects which I store in Google Firestore database (native mode) using Objectify 6.0.7. Storing, deleting, and querying objects all work fine, but a query with an orderBy clause on a single field fails with “no matching index found”. The exact same code works perfectly in a Datastore project (so the Java code is not in question).

I could not find clear documentation as to whether Objectify can work with Firestore and I suspect this is the issue. Thoughts?

This is the query:

ofy().load().type(Flight.class).order("-date").list();

and this is a sample record from that collection (French locale, but the date objects are valid):

airTime: "0.8666666666666667"
date: 20 décembre 2020 à 19:51:41 UTC-5
engineStartTime: 20 décembre 2020 à 19:51:41 UTC-5
engineStopTime: 20 décembre 2020 à 21:14:41 UTC-5
flightTime: 1.3833333333333333
from: "CYQB"
landingTime: 20 décembre 2020 à 21:08:41 UTC-5
takeOffTime: 20 décembre 2020 à 20:16:41 UTC-5
to: "CYVB"

Using an ascending order, e.g. order("desc") also fails, but removing the .order('-desc') function from the query altogether does not cause any error but of course returns results in random order.

I understand from the documentation that all single-field indexes should be created by default in Firestore and I see no way to create a single field index in the console. I therefore assume that an index exists for the date field used in the order function.

Advertisement

Answer

Objectify v6 uses the com.google.cloud:google-cloud-datastore library as a low-level API. I’m pretty sure that library only works in Datastore Mode. Google has a completely different (and much more primitive) Java library for Firestore Mode.

So I think for now you need to use Datastore Mode and not Firestore Mode.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement