[#1838] Create index only if it doesn't exist

We do so by creating a unique index name that's specific to each pair
resource_id + field_name. Before trying to create an index, we check if an
index with this same name exist, and only create it if it doesn't.
[#1838] Refactor tests to be less flaky

Instead of asserting the number of indexes created, we now assert on the actual
index names.