` Query query = firestore.collection(“users”)
.document(myUserID)
.collection(“unseen_profiles”)
.whereEqualTo(“country”, myProfileCountryFilter);
if (!myProfileGenderFilter.isEmpty() && !myProfileGenderFilter.equalsIgnoreCase("everyone")) {
query = query.whereEqualTo("gender", myProfileGenderFilter);
}
if (heightFilterOn) {
query = query.whereGreaterThanOrEqualTo("height", minimumHeight);
}
if (weightFilterOn) {
query = query.whereLessThanOrEqualTo("weight", maximumWeight);
}
if (customAgeFilterOn) {
query = query.whereGreaterThanOrEqualTo("age", minimumAge)
.whereLessThanOrEqualTo("age", maximumAge);
}
if (lookingForFilterOn) {
query = query.whereArrayContainsAny("looking_for", lookingForArray);
}
if (personalityTypeFilterOn) {
query = query.whereIn("personality_type", personalityTypeList);
}
if (homeCountryFilterOn) {
query = query.whereEqualTo("home_country", homeCountryFilter);
}
// Add orderBy for timestamp
query = query.orderBy("timestamp");
// Configure the adapter options
PagingConfig config = new PagingConfig(
10, // PageSize
5, // PrefetchDistance
false // EnablePlaceholders
);
FirestorePagingOptions<DataModel> options = new FirestorePagingOptions.Builder<DataModel>()
.setLifecycleOwner(this) // Lifecycle owner
.setQuery(query, config, DataModel.class) // Query and the model class
.build();`
Now when different conditions satisfy, every time the app crashes & ask to create an index. But considering combination of the above conditions, if I have to create index for all of them then a huge number of index needs to be created.
I heard that if I need to create many indexes then maybe I am not using query efficiently or maybe I need to optimize the data structure. But in my case I don’t find any other viable options to achieve desired functionality with the query. Am I missing anything? If I am not missing anything then how can I manage creating such large of indexes with time efficiency? Is there any way I can automate creating index when the query requires without the app crashing or query failing?