Firebase firestore have mainly 2 types of queries
- Simple queries
- Compound queries
- Simple queries have only where condition, so they don't need database indexes, like
FirebaseFirestore.getInstance().collection("cities")
.whereEqualTo("capital", true)
.get()
.addOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Log.d(TAG, document.getId() + " => " + document.getData());
}
} else {
Log.d(TAG, "Error getting documents: ", task.getException());
}
}
});
- Your query is compound query which has multiple Where queries chained together which needs composite index, you can either create composite index in firebase console or create composite index using error message, creating index using error message is easier one, which is printed in your log message, as it handles the fields and sorting order and directly creates index for you