# When to index a string with hash instead of exact?

**URL:** <https://discuss.dgraph.io/t/when-to-index-a-string-with-hash-instead-of-exact/2913>\
**Category:** Dgraph\
**Created:** [July 19, 2018, 4:35pm UTC](https://discuss.dgraph.io/t/when-to-index-a-string-with-hash-instead-of-exact/2913 "2018-07-19T16:35:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tlmichael](https://avatars.discourse-cdn.com/v4/letter/t/97f17d/32.png) [@tlmichael](https://discuss.dgraph.io/u/tlmichael)\
**Post date:** [July 19, 2018, 4:35pm UTC](https://discuss.dgraph.io/t/when-to-index-a-string-with-hash-instead-of-exact/2913/1 "2018-07-19T16:35:49Z")

</div>

I’m aware that the [documentation here](https://tour.dgraph.io/search/1/) mention that `hash` does the same as `exact` but hashes string.

Am I correct in the assumption that the hashing is done using MD5, and therefore we should preferably use `exact` index if we know the string will be less than 32 characters, whereas we should use `hash` index if the string will be more than 32 characters?

---

<div class="post-metadata">

**Author:** ![mrjn](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/mrjn/32/775_2.png) [@mrjn](https://discuss.dgraph.io/u/mrjn)\
**Post date:** [July 19, 2018, 5:02pm UTC](https://discuss.dgraph.io/t/when-to-index-a-string-with-hash-instead-of-exact/2913/2 "2018-07-19T17:02:02Z")

</div>

Dgraph takes care of dealing with collissions. So, functionality wise, they’re exactly the same. But, they matter in terms of storage and performance. If you expect strings longer than say 16 bytes, I’d suggest using hash. In general, hash is a good idea – exact is useful only if you already have a string whose length is confined to a small limit (like username).

---

<div class="post-metadata">

**Author:** ![tlmichael](https://avatars.discourse-cdn.com/v4/letter/t/97f17d/32.png) [@tlmichael](https://discuss.dgraph.io/u/tlmichael)\
**Post date:** [July 19, 2018, 5:07pm UTC](https://discuss.dgraph.io/t/when-to-index-a-string-with-hash-instead-of-exact/2913/3 "2018-07-19T17:07:55Z")

</div>

Thanks, appreciate it 🙂

---

<div class="post-metadata">

**Author:** ![mrjn](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/mrjn/32/775_2.png) [@mrjn](https://discuss.dgraph.io/u/mrjn)\
**Post date:** [July 29, 2019, 6:28pm UTC](https://discuss.dgraph.io/t/when-to-index-a-string-with-hash-instead-of-exact/2913/4 "2019-07-29T18:28:30Z")

</div>

> [@mrjn](#):
>
> Dgraph takes care of dealing with collissions.

Update: Dgraph no longer does collision detection with hashes for better performance. However, I think we use a 128-bit hash to decrease the chance of collisions significantly (been a while, need to verify).
