1

Android/Java:

In firestore document, I have a field "name" which have value America

I want to create a firebase query in the way that if I pass ame in that so it does return all the documents which have ame in the vale of their name field.

firebaseFirestore.collection("country").whereContains("name", "ame");

In short, I want to search/filter firestore data using substring.

PradyumanDixit
  • 2,372
  • 2
  • 12
  • 20
Vikas Rana
  • 33
  • 2
  • 9
  • There is no way to search for substrings in Cloud Firestore. The documentation recommends integrating with a third-party service like Algolia for that. See https://firebase.google.com/docs/firestore/solutions/search. Also see https://stackoverflow.com/a/46568525, https://stackoverflow.com/a/50434226, https://stackoverflow.com/a/47133345, https://stackoverflow.com/a/47916173 – Frank van Puffelen Oct 19 '18 at 13:22
  • Hey @VikasRana do mark the answer as correct, by clicking the V or tick mar like looking button next to the answer, as this helps the Stack Overflow readers and I'd appreciate that too. Cheers! :) – PradyumanDixit Nov 15 '18 at 04:02

1 Answers1

0

For this there is something that "MIGHT" help, it is called array-contains query. Know more about that here, https://firebase.googleblog.com/2018/08/better-arrays-in-cloud-firestore.html.

It is used in a way like this:

collection("collectionPath").
    where("searchTermsArray", "array-contains", "term").get()

Otherwise there's also an option of using external service like Algolia or ElasticSearch for that.

PradyumanDixit
  • 2,372
  • 2
  • 12
  • 20