Skip to content
Snippets Groups Projects
Commit 2791cbdd authored by Neelesh Thakur's avatar Neelesh Thakur
Browse files

handle special characters in attribute names

parent 8377e471
No related branches found
No related tags found
1 merge request!208serialize index mapping response to valid JSON for consumption
Pipeline #68127 passed with warnings
......@@ -14,6 +14,8 @@
package org.opengroup.osdu.indexer.service;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.apache.http.HttpStatus;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
......@@ -31,6 +33,8 @@ import org.springframework.stereotype.Service;
import org.springframework.web.context.annotation.RequestScope;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Map;
import java.util.Objects;
@Service
......@@ -85,7 +89,8 @@ public class MappingServiceImpl implements IMappingService {
request.indices(index);
request.setTimeout(REQUEST_TIMEOUT);
GetMappingsResponse response = client.indices().getMapping(request, RequestOptions.DEFAULT);
return response.mappings().get(index).getSourceAsMap().toString();
Type type = new TypeToken<Map<String, Object>>() {}.getType();
return new Gson().toJson(response.mappings().get(index).getSourceAsMap(), type);
} catch (IOException e) {
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Unknown error", String.format("Error retrieving mapping for kind %s", this.elasticIndexNameResolver.getKindFromIndexName(index)), e);
}
......
......@@ -2,7 +2,7 @@
{
"id": "tenant1:<kindSubType>:testMappingSync<timestamp>",
"data": {
"FullName": "The Open Group",
"Full Name": "The Open Group",
"Address": "Burlington, MA",
"Phone": "781-564-9200"
}
......
......@@ -20,7 +20,7 @@
},
"data": {
"properties": {
"FullName": {
"Full Name": {
"type": "text",
"fields": {
"keyword": {
......
......@@ -4,7 +4,7 @@
"authority": "tenant1",
"source": "indexer",
"entityType": "test-mapping--Sync",
"schemaVersionMajor": "1",
"schemaVersionMajor": "2",
"schemaVersionMinor": "0",
"schemaVersionPatch": "0"
},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment