diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceImpl.java index 13b9e50d221e1147f9eb33f005864b88c83b9ef4..95f1c504f9eca6e03027fd4e14e8389fb8cb61bc 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceImpl.java @@ -23,14 +23,14 @@ import java.util.Set; import javax.inject.Inject; import org.apache.http.HttpStatus; import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest; -import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse; -import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.client.Request; import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.Response; import org.elasticsearch.client.RestHighLevelClient; +import org.elasticsearch.client.indices.GetFieldMappingsRequest; +import org.elasticsearch.client.indices.GetFieldMappingsResponse; +import org.elasticsearch.client.indices.PutMappingRequest; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.reindex.BulkByScrollResponse; @@ -183,12 +183,10 @@ public class IndexerMappingServiceImpl extends MappingServiceImpl implements Ind try { GetFieldMappingsResponse response = client.indices().getFieldMapping(request, RequestOptions.DEFAULT); if (response != null && !response.mappings().isEmpty()) { - final Map<String, Map<String, Map<String, GetFieldMappingsResponse.FieldMappingMetadata>>> mappings = response.mappings(); + final Map<String, Map<String, GetFieldMappingsResponse.FieldMappingMetadata>> mappings = response.mappings(); for (String index : indices) { - //extract mapping of each index - final Map<String, Map<String, GetFieldMappingsResponse.FieldMappingMetadata>> indexMapping = mappings.get(index); - if (indexMapping != null && !indexMapping.isEmpty()) { - indexMappingMap.put(index, indexMapping); + if (mappings != null && !mappings.isEmpty()) { + indexMappingMap.put(index, mappings); } } } @@ -207,9 +205,8 @@ public class IndexerMappingServiceImpl extends MappingServiceImpl implements Ind log.error(String.format("Could not find type of the mappings for index: %s.", index)); return false; } - - request.type(type); - request.timeout(REQUEST_TIMEOUT); + + request.setTimeout(REQUEST_TIMEOUT); Map<String, GetFieldMappingsResponse.FieldMappingMetadata> metaData = indexMapping.get(type); if(metaData==null || metaData.get("data." + fieldName)==null) { log.error(String.format("Could not find field: %s in the mapping of index: %s.", fieldName, index)); @@ -316,9 +313,8 @@ public class IndexerMappingServiceImpl extends MappingServiceImpl implements Ind try { if (mapping != null) { PutMappingRequest request = new PutMappingRequest(index); - request.type(type); request.source(mapping, XContentType.JSON); - request.timeout(REQUEST_TIMEOUT); + request.setTimeout(REQUEST_TIMEOUT); AcknowledgedResponse response = client.indices().putMapping(request, RequestOptions.DEFAULT); return response.isAcknowledged(); } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerServiceImpl.java index 36f91af2405098e188a4113b009e165dfd4500be..1472d240a466464d825b77b9d2acc695f68b17fa 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerServiceImpl.java @@ -368,10 +368,10 @@ public class IndexerServiceImpl implements IndexerService { String index = this.elasticIndexNameResolver.getIndexNameFromKind(record.getKind()); if (operation == OperationType.create) { - IndexRequest indexRequest = new IndexRequest(index, record.getType(), record.getId()).source(this.gson.toJson(sourceMap), XContentType.JSON); + IndexRequest indexRequest = new IndexRequest(index).id(record.getId()).source(this.gson.toJson(sourceMap), XContentType.JSON); bulkRequest.add(indexRequest); } else if (operation == OperationType.update) { - UpdateRequest updateRequest = new UpdateRequest(index, record.getType(), record.getId()).upsert(this.gson.toJson(sourceMap), XContentType.JSON); + UpdateRequest updateRequest = new UpdateRequest(index, record.getId()).upsert(this.gson.toJson(sourceMap), XContentType.JSON); bulkRequest.add(updateRequest); } } @@ -385,13 +385,10 @@ public class IndexerServiceImpl implements IndexerService { for (Map.Entry<String, List<String>> record : deleteRecordMap.entrySet()) { - String[] kindParts = record.getKey().split(":"); - String type = kindParts[2]; - String index = this.elasticIndexNameResolver.getIndexNameFromKind(record.getKey()); for (String id : record.getValue()) { - DeleteRequest deleteRequest = new DeleteRequest(index, type, id); + DeleteRequest deleteRequest = new DeleteRequest(index, id); bulkRequest.add(deleteRequest); } } @@ -406,8 +403,6 @@ public class IndexerServiceImpl implements IndexerService { List<String> failureRecordIds = new LinkedList<>(); if (bulkRequest.numberOfActions() == 0) return failureRecordIds; - - try { BulkResponse bulkResponse = restClient.bulk(bulkRequest, RequestOptions.DEFAULT); diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndicesServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndicesServiceImpl.java index 972cb01025549c09869e85a2cee73406e4252dd5..ec68f6cccbdc88ea0f8a605c90f301fba53e56bc 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndicesServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndicesServiceImpl.java @@ -22,9 +22,7 @@ import org.apache.http.HttpStatus; import org.apache.http.util.EntityUtils; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchStatusException; - import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; -import org.elasticsearch.action.admin.indices.get.GetIndexRequest; import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.client.Request; import org.elasticsearch.client.RequestOptions; @@ -32,6 +30,7 @@ import org.elasticsearch.client.Response; import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.client.indices.CreateIndexRequest; import org.elasticsearch.client.indices.CreateIndexResponse; +import org.elasticsearch.client.indices.GetIndexRequest; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentType; @@ -96,6 +95,7 @@ public class IndicesServiceImpl implements IndicesService { String mappingJsonString = new Gson().toJson(mapping, Map.class); request.mapping(mappingJsonString,XContentType.JSON); } + request.setTimeout(REQUEST_TIMEOUT); CreateIndexResponse response = client.indices().create(request, RequestOptions.DEFAULT); // cache the index status boolean indexStatus = response.isAcknowledged() && response.isShardsAcknowledged(); @@ -129,8 +129,7 @@ public class IndicesServiceImpl implements IndicesService { //In case the format of cache changes then clean the cache this.indicesExistCache.delete(index); } - GetIndexRequest request = new GetIndexRequest(); - request.indices(index); + GetIndexRequest request = new GetIndexRequest(index); boolean exists = client.indices().exists(request, RequestOptions.DEFAULT); if (exists) this.indicesExistCache.put(index, true); return exists; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/MappingServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/MappingServiceImpl.java index 6b52cc19b4a8e9f56339ce41bebfc79db0aa0c54..3f067f74ef2e7cf7762f196d428fd7b4f889fed2 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/MappingServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/MappingServiceImpl.java @@ -15,10 +15,10 @@ package org.opengroup.osdu.indexer.service; import org.apache.http.HttpStatus; -import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; -import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RestHighLevelClient; +import org.elasticsearch.client.indices.GetMappingsRequest; +import org.elasticsearch.client.indices.GetMappingsResponse; import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; import org.opengroup.osdu.core.common.search.IndicesService; diff --git a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/RecordSteps.java b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/RecordSteps.java index 716b6e08d9ad0ac4e4fd31549746bcc5ef94f20c..c040e0d09881cf9c5c8cb5b80e929e1585c1e9ae 100644 --- a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/RecordSteps.java +++ b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/RecordSteps.java @@ -8,7 +8,6 @@ import com.sun.jersey.api.client.ClientResponse; import cucumber.api.DataTable; import lombok.extern.java.Log; import org.elasticsearch.cluster.metadata.MappingMetadata; -import org.elasticsearch.common.collect.ImmutableOpenMap; import org.opengroup.osdu.core.common.model.entitlements.Acl; import org.opengroup.osdu.models.Setup; import org.opengroup.osdu.models.TestIndex; @@ -118,7 +117,7 @@ public class RecordSteps extends TestsBase { public void i_should_get_the_elastic_for_the_tenant_testindex_timestamp_well_in_the_Elastic_Search(String expectedMapping, String type, String index) throws Throwable { index = generateActualName(index, timeStamp); - ImmutableOpenMap<String, MappingMetadata> elasticMapping = elasticUtils.getMapping(index); + Map<String, MappingMetadata> elasticMapping = elasticUtils.getMapping(index); assertNotNull(elasticMapping); MappingMetadata typeMapping = elasticMapping.get(type); diff --git a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/util/ElasticUtils.java b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/util/ElasticUtils.java index d72de5ea9e57ace7e65b0dc8b6d55a605c91898c..43a8d1b9cee47eb7cdc9e2397ba9206adc68870c 100644 --- a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/util/ElasticUtils.java +++ b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/util/ElasticUtils.java @@ -33,12 +33,7 @@ import org.apache.http.ssl.SSLContextBuilder; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.client.indices.CloseIndexRequest; -import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; -import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; -import org.elasticsearch.action.admin.indices.get.GetIndexRequest; -import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; -import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; import org.elasticsearch.action.bulk.BulkRequest; @@ -48,6 +43,11 @@ import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.client.*; +import org.elasticsearch.client.indices.CreateIndexRequest; +import org.elasticsearch.client.indices.CreateIndexResponse; +import org.elasticsearch.client.indices.GetIndexRequest; +import org.elasticsearch.client.indices.GetMappingsRequest; +import org.elasticsearch.client.indices.GetMappingsResponse; import org.elasticsearch.cluster.metadata.MappingMetadata; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.settings.Settings; @@ -99,9 +99,9 @@ public class ElasticUtils { // creating index + add mapping to the index log.info("Creating index with name: " + index); - CreateIndexRequest request = new CreateIndexRequest(index, settings); + CreateIndexRequest request = new CreateIndexRequest(index).settings(settings); request.source("{\"mappings\":" + mapping + "}", XContentType.JSON); - request.timeout(REQUEST_TIMEOUT); + request.setTimeout(REQUEST_TIMEOUT); CreateIndexResponse response = client.indices().create(request, RequestOptions.DEFAULT); //wait for ack @@ -234,13 +234,13 @@ public class ElasticUtils { } } - public ImmutableOpenMap<String, MappingMetadata> getMapping(String index) throws IOException { + public Map<String, MappingMetadata> getMapping(String index) throws IOException { try (RestHighLevelClient client = this.createClient(username, password, host)) { GetMappingsRequest request = new GetMappingsRequest(); request.indices(index); GetMappingsResponse response = client.indices().getMapping(request, RequestOptions.DEFAULT); - ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetadata>> allMappings = response.mappings(); - return allMappings.get(index); + Map<String, MappingMetadata> mappings = response.mappings(); + return mappings; } } @@ -276,7 +276,7 @@ public class ElasticUtils { for (Map<String, Object> record : testRecords) { String id = (String) record.get("id"); Map<String, Object> mapData = gson.fromJson(gson.toJson(record), Map.class); - IndexRequest indexRequest = new IndexRequest(index, kind.split(":")[2], id).source(mapData); + IndexRequest indexRequest = new IndexRequest(index).id(id).source(mapData); dataList.add(indexRequest); } } catch (Exception e) { @@ -362,8 +362,7 @@ public class ElasticUtils { private boolean createRestClientAndCheckIndexExist(String index) { try (RestHighLevelClient client = this.createClient(username, password, host)) { - GetIndexRequest request = new GetIndexRequest(); - request.indices(index); + GetIndexRequest request = new GetIndexRequest(index); return client.indices().exists(request, RequestOptions.DEFAULT); } catch (IOException e) { log.log(Level.INFO, String.format("Error getting index: %s %s", index, e.getMessage()));