diff --git a/Documentation/config-gerrit.txt b/Documentation/config-gerrit.txt index 86375670e6..c96e6855f3 100644 --- a/Documentation/config-gerrit.txt +++ b/Documentation/config-gerrit.txt @@ -3143,11 +3143,9 @@ WARNING: Support for Elasticsearch is still experimental and is not recommended for production use. For compatibility information, please refer to the link:https://www.gerritcodereview.com/elasticsearch.html[project homepage]. -When using Elasticsearch version 5.6, the open and closed changes are -indexed in a single index, separated into types `open_changes` and `closed_changes` -respectively. When using version 6.2 or later, the open and closed changes are -merged into the default `_doc` type. The latter is also used for the accounts and -groups indices starting with Elasticsearch 6.2. +In Elasticsearch version 6.2 or later, the open and closed changes are merged +into the default `_doc` type. The latter is also used for the accounts and groups +indices starting with Elasticsearch 6.2. Note that when Gerrit is configured to use Elasticsearch, the Elasticsearch server(s) must be reachable during the site initialization. diff --git a/java/com/google/gerrit/elasticsearch/AbstractElasticIndex.java b/java/com/google/gerrit/elasticsearch/AbstractElasticIndex.java index ac60ddcfd8..2ab9c929b7 100644 --- a/java/com/google/gerrit/elasticsearch/AbstractElasticIndex.java +++ b/java/com/google/gerrit/elasticsearch/AbstractElasticIndex.java @@ -126,8 +126,7 @@ abstract class AbstractElasticIndex implements Index { SitePaths sitePaths, Schema schema, ElasticRestClientProvider client, - String indexName, - String indexType) { + String indexName) { this.config = config; this.sitePaths = sitePaths; this.schema = schema; @@ -136,16 +135,7 @@ abstract class AbstractElasticIndex implements Index { this.indexName = config.getIndexName(indexName, schema.getVersion()); this.indexNameRaw = indexName; this.client = client; - this.type = client.adapter().getType(indexType); - } - - AbstractElasticIndex( - ElasticConfiguration cfg, - SitePaths sitePaths, - Schema schema, - ElasticRestClientProvider client, - String indexName) { - this(cfg, sitePaths, schema, client, indexName, indexName); + this.type = client.adapter().getType(); } @Override @@ -211,8 +201,8 @@ abstract class AbstractElasticIndex implements Index { protected abstract String getId(V v); - protected String getMappingsForSingleType(String candidateType, MappingProperties properties) { - return getMappingsFor(client.adapter().getType(candidateType), properties); + protected String getMappingsForSingleType(MappingProperties properties) { + return getMappingsFor(client.adapter().getType(), properties); } protected String getMappingsFor(String type, MappingProperties properties) { @@ -228,8 +218,8 @@ abstract class AbstractElasticIndex implements Index { return gson.toJson(mappings); } - protected String delete(String type, K id) { - return new DeleteRequest(id.toString(), indexName, type, client.adapter()).toString(); + protected String getDeleteRequest(K id) { + return new DeleteRequest(id.toString(), indexName).toString(); } protected abstract V fromDocument(JsonObject doc, Set fields); diff --git a/java/com/google/gerrit/elasticsearch/ElasticAccountIndex.java b/java/com/google/gerrit/elasticsearch/ElasticAccountIndex.java index d0b70ae6bd..7f05817723 100644 --- a/java/com/google/gerrit/elasticsearch/ElasticAccountIndex.java +++ b/java/com/google/gerrit/elasticsearch/ElasticAccountIndex.java @@ -74,9 +74,7 @@ public class ElasticAccountIndex extends AbstractElasticIndex(schema, as)); + BulkRequest bulk = new IndexRequest(getId(as), indexName).add(new UpdateRequest<>(schema, as)); String uri = getURI(type, BULK); Response response = postRequest(uri, bulk, getRefreshParam()); @@ -98,12 +96,12 @@ public class ElasticAccountIndex extends AbstractElasticIndex @Override public void replace(ChangeData cd) throws IOException { - String deleteIndex; - String insertIndex; - - try { - if (cd.change().getStatus().isOpen()) { - insertIndex = OPEN_CHANGES; - deleteIndex = CLOSED_CHANGES; - } else { - insertIndex = CLOSED_CHANGES; - deleteIndex = OPEN_CHANGES; - } - } catch (OrmException e) { - throw new IOException(e); - } - - ElasticQueryAdapter adapter = client.adapter(); - BulkRequest bulk = - new IndexRequest(getId(cd), indexName, adapter.getType(insertIndex), adapter) - .add(new UpdateRequest<>(schema, cd)); - if (adapter.deleteToReplace()) { - bulk.add(new DeleteRequest(cd.getId().toString(), indexName, deleteIndex, adapter)); - } + BulkRequest bulk = new IndexRequest(getId(cd), indexName).add(new UpdateRequest<>(schema, cd)); String uri = getURI(type, BULK); Response response = postRequest(uri, bulk, getRefreshParam()); @@ -185,19 +160,13 @@ class ElasticChangeIndex extends AbstractElasticIndex } @Override - protected String getDeleteActions(Id c) { - if (!client.adapter().useV5Type()) { - return delete(client.adapter().getType(), c); - } - return delete(OPEN_CHANGES, c) + delete(CLOSED_CHANGES, c); + protected String getDeleteActions(Change.Id c) { + return getDeleteRequest(c); } @Override protected String getMappings() { - if (!client.adapter().useV5Type()) { - return getMappingsFor(client.adapter().getType(), mapping.changes); - } - return gson.toJson(ImmutableMap.of(MAPPINGS, mapping)); + return getMappingsFor(client.adapter().getType(), mapping.changes); } @Override diff --git a/java/com/google/gerrit/elasticsearch/ElasticGroupIndex.java b/java/com/google/gerrit/elasticsearch/ElasticGroupIndex.java index e74f2084fa..2c10a2c766 100644 --- a/java/com/google/gerrit/elasticsearch/ElasticGroupIndex.java +++ b/java/com/google/gerrit/elasticsearch/ElasticGroupIndex.java @@ -73,8 +73,7 @@ public class ElasticGroupIndex extends AbstractElasticIndex(schema, group)); + new IndexRequest(getId(group), indexName).add(new UpdateRequest<>(schema, group)); String uri = getURI(type, BULK); Response response = postRequest(uri, bulk, getRefreshParam()); @@ -96,12 +95,12 @@ public class ElasticGroupIndex extends AbstractElasticIndex(schema, projectState)); String uri = getURI(type, BULK); @@ -96,12 +96,12 @@ public class ElasticProjectIndex extends AbstractElasticIndex