# Index data from firebase db "so called index" for tinder-like app

**URL:** <https://discuss.elastic.co/t/index-data-from-firebase-db-so-called-index-for-tinder-like-app/65100>\
**Category:** Elasticsearch\
**Created:** [November 5, 2016, 2:17pm UTC](https://discuss.elastic.co/t/index-data-from-firebase-db-so-called-index-for-tinder-like-app/65100 "2016-11-05T14:17:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![florianbepunkt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/florianbepunkt/32/12992_2.png) [@florianbepunkt](https://discuss.elastic.co/u/florianbepunkt)\
**Post date:** [November 5, 2016, 2:17pm UTC](https://discuss.elastic.co/t/index-data-from-firebase-db-so-called-index-for-tinder-like-app/65100/1 "2016-11-05T14:17:48Z")

</div>

I'm working on a tinder-like app. We use a firebase database and index user profiles in our firebase db with elasticsearch. This works fine but I struggle on how to exclude already swiped profiles from query.

So scenario is this: User queries for profiles and swipes the profiles left or right. Already swiped profiles should be excluded from next query.

Since I can't store arrays in firebase I store already swiped users as a "so called index" like this

```
{
  "uniqueUserID1-swipedata : {
    "alreadySwipedUsers" : {
      "uniqueUserID2" : true,
      "uniqueUserID3" : true,
      "uniqueUserID4" : true,
      …
    }
  },
  "uniqueUserID2-swipedata" : {
    "excludeFromQuery" : {
      "uniqueUserID1" : true
    }
  },
…
}

```

What would be the best approach to get this data into elasticsearch so if I query userProfiles I can exclude already swiped users.

Basically I was thinking about two approaches, but are completely open to suggestions:

**Approach A:**  
Have two index, one for userProfiles and one for userSwipeData. Use terms lookup in my user profiles query in a must\_not filter to exclude already swiped profiles.

```
"must_not": [
  {
    "terms" : {
        "_id" : {
            "index" : "userSwipeData",
            "type" : "userSwipeData",
            "id" : "current-user-id-of-querying-user",
            "path" : "excludeFromQuery"
        }
    }
  }
]

```

_Problem with this is:_ My excludeFromQuery field would need to be an array as far as I understand. But I don't have an array but this so-called-index structure from above. So here I'm stuck… I'm not sure how to index my firebase data in a way to use it with a terms lookup. If anyone has an idea on how to make this work, this would be much appreciated.

**Approach B:**  
I don't use a seperate index for already swiped users but store my firebase data structure from above as an inner object in my user documents. Then I could use an exists query to check if a certain user id already exists as a field in the inner object.

_Problem:_ I don't think this would scale well, since the inner document theoretically could contain hundreds or even thousand of unique fields.

**Approach C:**  
Give up on the idea of synching data between firebase and elasticsearch. I could store already wiped users purely on elasticsearch like in appaoch A. So if a user swipes another user, I could to a partial update to userSwipeData index and append the swiped user to the array of already swiped users. I guess this could work, but I don't like the idea of giving up on synching data between firebase and elasticsearch.

Any advice on how to tackle this would be greatly appreciated.

Thank you,  
Florian

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 3, 2016, 2:17pm UTC](https://discuss.elastic.co/t/index-data-from-firebase-db-so-called-index-for-tinder-like-app/65100/2 "2016-12-03T14:17:59Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
