Home » Android » android – It is possible to have a contains search query in firebase?

android – It is possible to have a contains search query in firebase?

Posted by: admin June 15, 2020 Leave a comment


I tried this:

Query firebaseSearchQuery = 

but i want something like this

Query firebaseSearchQuery = 

it is possible ?

How to&Answers:

For small datasets you can use the following code:

ValueEventListener valueEventListener = new ValueEventListener() {
    public void onDataChange(DataSnapshot dataSnapshot) {
        List<String> list = new ArrayList<>();
        for(DataSnapshot ds : dataSnapshot.getChildren()) {
            String from = ds.child("from").getValue(String.class);

        for(String str : list) {
            if(str.contains(searchText)) {
                Log.d("TAG", "String found!");

    public void onCancelled(DatabaseError databaseError) {}

This solution is not recommended for large datasets because you’ll need to download the entire node in order to make a search. In this case, Algolia or Elasticsearch are recommended.

If you intend to use Cloud Firestore, I recommend you to see my answer from this post. For more information, I also recommend you see this video.


You need maybe this:

Query firebaseSearchQuery = myRef.orderByChild("from").equalTo(searchText + "\uf8ff");


I guess it is not possible using firebase, it needs a special service in order to be done. A service that has to do with advanced searching (something like elastic search).