Skip to content
Snippets Groups Projects

Elastic search EOL version upgrade

Closed Harshika Dhoot requested to merge es-version into azure/m18-master
Files
11
@@ -19,10 +19,8 @@ import com.google.gson.reflect.TypeToken;
import com.lambdaworks.redis.RedisException;
import org.elasticsearch.ElasticsearchException;
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.*;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.client.indices.PutMappingRequest;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.xcontent.XContentType;
@@ -72,7 +70,7 @@ public class IndexerMappingServiceImpl extends MappingServiceImpl implements IMa
Map<String, Object> mappingMap = this.getIndexMappingFromRecordSchema(schema);
String mapping = new Gson().toJson(mappingMap, Map.class);
this.createMappingWithJson(client, index, schema.getType(), mapping, merge);
this.createMappingWithJson(client, index, mapping, merge);
return mapping;
}
@@ -211,7 +209,7 @@ public class IndexerMappingServiceImpl extends MappingServiceImpl implements IMa
documentMapping.put(Constants.PROPERTIES, properties);
String mapping = new Gson().toJson(documentMapping, Map.class);
this.createMappingWithJson(restClient, index, "_doc", mapping, true);
this.createMappingWithJson(restClient, index, mapping, true);
log.info(String.format("Creating Mapping for index %s, %s", index, mapping));
this.indexCache.put(cacheKey, true);
@@ -222,17 +220,16 @@ public class IndexerMappingServiceImpl extends MappingServiceImpl implements IMa
*
* @param client Elasticsearch client
* @param index Index name
* @param type Type name
* @param mapping Mapping if any, null if no specific mapping
* @param merge Try to merge mapping if type already exists
* @throws IOException if cannot create index mapping with input json
*/
private void createMappingWithJson(RestHighLevelClient client, String index, String type, String mapping, boolean merge)
private void createMappingWithJson(RestHighLevelClient client, String index, String mapping, boolean merge)
throws IOException {
boolean mappingExist = isTypeExist(client, index, type);
boolean mappingExist = isTypeExist(client, index);
if (merge || !mappingExist) {
createTypeWithMappingInElasticsearch(client, index, type, mapping);
createTypeWithMappingInElasticsearch(client, index, mapping);
}
}
@@ -241,15 +238,15 @@ public class IndexerMappingServiceImpl extends MappingServiceImpl implements IMa
*
* @param client Elasticsearch client
* @param index Index name
* @param type Type name
* @return true if type already exists
* @throws IOException in case Elasticsearch responded with a status code that indicated an error
*/
public boolean isTypeExist(RestHighLevelClient client, String index, String type) throws IOException {
public boolean isTypeExist(RestHighLevelClient client, String index) throws IOException {
Request request = new Request("HEAD", "/" + index + "/_mapping/" + type);
Response response = client.getLowLevelClient().performRequest(request);
return response.getStatusLine().getStatusCode() == 200;
GetIndexRequest getIndexRequest = new GetIndexRequest(index);
IndicesClient indices = client.indices();
boolean exists = indices.exists(getIndexRequest, RequestOptions.DEFAULT);
return exists;
}
/**
@@ -257,15 +254,13 @@ public class IndexerMappingServiceImpl extends MappingServiceImpl implements IMa
*
* @param client Elasticsearch client
* @param index Index name
* @param type Type name
* @param mapping Mapping if any, null if no specific mapping
* @throws IOException if mapping cannot be created
*/
private Boolean createTypeWithMappingInElasticsearch(RestHighLevelClient client, String index, String type, String mapping) throws IOException {
private Boolean createTypeWithMappingInElasticsearch(RestHighLevelClient client, String index, String mapping) throws IOException {
Preconditions.checkNotNull(client, "client cannot be null");
Preconditions.checkNotNull(index, "index cannot be null");
Preconditions.checkNotNull(type, "type cannot be null");
try {
if (mapping != null) {
@@ -279,7 +274,7 @@ public class IndexerMappingServiceImpl extends MappingServiceImpl implements IMa
throw new AppException(
e.status().getStatus(),
e.getMessage(),
String.format("Could not create type mapping %s/%s.", index, type),
String.format("Could not create mapping %s.", index),
String.format("Failed creating mapping: %s", mapping),
e);
}
Loading