Fix filtering measurements on related_entity_id.

Included spec for regression testing