Fix the online index for changes when upgrading ES gerrit site

Previously, when using ElasticSearch as main index engine and
upgrading the gerrit site from 2.14 to 2.15, the changes were not
visible in the UI even when OnlineIndexer logs showed that indexing
was successful.

Reason: After migration, new indices were never created with the custom
mappings and elasticsearch created the default mappings with the
standard fields used in the indices. This resulted in a mismatch between
the mapping types and therefore changes were not visible in the UI.

For example:

The "changes" index in gerrit use two types of mappings - "open_changes"
and "closed_changes". When no index was created by gerrit and
onlineIndexer was called while running gerrit with the migrated site,
elasticsearch created only "open_changes" mapping type resulting in
conflicts between two different versions of the same indices.

This change resolves the inconsistencies between offline and online
reindex by deleting all the previously existing indices and creating the
new ones.

Bug: Issue 8806
Change-Id: I51ee5bfeb2a154630955b3c94b78fda7d050610d
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/index/OnlineReindexer.java b/gerrit-server/src/main/java/com/google/gerrit/server/index/OnlineReindexer.java
index ed1d8b5..ee2a76e 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/index/OnlineReindexer.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/index/OnlineReindexer.java
@@ -63,6 +63,8 @@
               try {
                 reindex();
                 ok = true;
+              } catch (IOException e) {
+                log.error("Online reindex of {} schema version {} failed", name, version(index), e);
               } finally {
                 running.set(false);
                 if (!ok) {
@@ -91,7 +93,7 @@
     return i.getSchema().getVersion();
   }
 
-  private void reindex() {
+  private void reindex() throws IOException {
     for (OnlineUpgradeListener listener : listeners) {
       listener.onStart(name, oldVersion, newVersion);
     }
@@ -106,6 +108,10 @@
         name,
         version(indexes.getSearchIndex()),
         version(index));
+
+    if (oldVersion != newVersion) {
+      index.deleteAll();
+    }
     SiteIndexer.Result result = batchIndexer.indexAll(index);
     if (!result.success()) {
       log.error(