# Checking the Existence of an Index Entry

**URL:** <https://forums.foundationdb.org/t/checking-the-existence-of-an-index-entry/2739>\
**Category:** Record Layer\
**Created:** [June 10, 2021, 6:26pm UTC](https://forums.foundationdb.org/t/checking-the-existence-of-an-index-entry/2739 "2021-06-10T18:26:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ricky.saltzer](https://avatars.discourse-cdn.com/v4/letter/r/f17d59/32.png) [@ricky.saltzer](https://forums.foundationdb.org/u/ricky.saltzer)\
**Post date:** [June 10, 2021, 6:26pm UTC](https://forums.foundationdb.org/t/checking-the-existence-of-an-index-entry/2739/1 "2021-06-10T18:26:54Z")

</div>

Using RecordLayer is there an easy way to check the existence of an index entry? I see there’s `loadIndexEntryRecord` which will check the index and then load the record associated with it (if it exists). I was wondering if there’s a way to skip that and to return `true` or `false` whether or not the index entry exists at all.

---

<div class="post-metadata">

**Author:** ![scgray](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/scgray/32/30_2.png) [@scgray](https://forums.foundationdb.org/u/scgray)\
**Post date:** [June 14, 2021, 1:46pm UTC](https://forums.foundationdb.org/t/checking-the-existence-of-an-index-entry/2739/2 "2021-06-14T13:46:39Z")

</div>

You can’t really scan an index and know if an entry is missing…to do this, you have to scan the records, compute the index entries from the records, **then** check to see if those entries are missing.

If, instead, you want to know if you have index entries that do not point to records, you can use:

> <https://github.com/FoundationDB/fdb-record-layer/blob/9153ac32400c071111a381027dd328f9025707db/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/FDBRecordStoreBase.java#L838>

The `IndexOrphanBehavior` option allows you to scan the index and return entries even if they do not point to records.

In general, though, if you are looking to check for any kind of index corruption (entries that don’t point to records, or records for which entries are missing), you can look at `IndexMaintainer.validateEntries()`. Currently, this is only implemented for `Value` indexes (validating things like aggregate indexes and Rank/Text indexes is much harder).
