Search code examples
javaandroidfirebase-realtime-databasefirebase-securitygeofire

Using an unspecified index. Your data will be downloaded and filtered on the client


How do you Retrieve this from firebase?

Firebase

Im trying create an app tracking the movement of the user but I cant get the location from the firebase. Ive Tried this code but the message below appears.

private void getEndLocation(){
    databaseReference = FirebaseDatabase.getInstance().getReference().child("User's Location");
    geoFire = new GeoFire(databaseReference);
    geoQuery = geoFire.queryAtLocation(new GeoLocation(adminCurrentLatitude,adminCurrentLongitude),10);
    geoQuery .removeAllListeners();

    geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
        @Override
        public void onKeyEntered(String key, GeoLocation location) {
            if(!userFound && requestType){
                userFound = true;
                userID = key;
                Log.d("Location", "onKeyEntered: "+userID);
            }
        }

        @Override
        public void onKeyExited(String key) {

        }

        @Override
        public void onKeyMoved(String key, GeoLocation location) {

        }

        @Override
        public void onGeoQueryReady() {

        }

        @Override
        public void onGeoQueryError(DatabaseError error) {

        }
    });
}

Here is the message that I received:

Using an unspecified index. Your data will be downloaded and filtered on the client. Consider adding '".indexOn": "g"' at User's Location to your security and Firebase Database rules for better performance


Solution

  • For the query in your code you need to define an index in the security rules of your database like this:

    {
      "rules": {
        ...
        "User's Location": {
          ".indexOn": "g"
        }
      }
    }
    

    Also see the Firebase documentation on indexing data and previous questions with the same error message.