Skip to content

Commit

Permalink
entity_auditx index Update field limits only if needed
Browse files Browse the repository at this point in the history
(cherry picked from commit fc2bf65)
  • Loading branch information
nikhilbonte21 committed Sep 29, 2023
1 parent 1e2a94e commit 889025c
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ void createSession() throws AtlasException {
LOG.info("Create ES index for entity audits in ES Based Audit Repo");
createAuditIndex();
}
if (isFieldLimitDifferent()) {
if (shouldUpdateFieldLimitSetting()) {
LOG.info("Updating ES total field limit");
updateFieldLimit();
}
Expand Down Expand Up @@ -328,24 +328,25 @@ private boolean createAuditIndex() throws IOException {
return isSuccess(response);
}

private boolean isFieldLimitDifferent() {
JsonNode fieldLimit;
private boolean shouldUpdateFieldLimitSetting() {
JsonNode currentFieldLimit;
try {
fieldLimit = getIndexFieldLimit();
currentFieldLimit = getIndexFieldLimit();
} catch (IOException e) {
LOG.error("Problem while retrieving the index field limit!", e);
return false;
}
Integer fieldLimitFromConfigurationFile = configuration.getInt(TOTAL_FIELD_LIMIT);
return fieldLimit == null || fieldLimitFromConfigurationFile.equals(fieldLimit.intValue());
return currentFieldLimit == null || fieldLimitFromConfigurationFile > currentFieldLimit.asInt();
}

private JsonNode getIndexFieldLimit() throws IOException {
Request request = new Request("GET", INDEX_NAME + "/_settings");
Response response = lowLevelClient.performRequest(request);
ObjectMapper objectMapper = new ObjectMapper();
String fieldName = INDEX_NAME + ".settings.index.mapping.total_fields.limit";
return objectMapper.readTree(copyToString(response.getEntity().getContent(), Charset.defaultCharset())).get(fieldName);
String fieldPath = String.format("/%s/settings/index/mapping/total_fields/limit", INDEX_NAME);

return objectMapper.readTree(copyToString(response.getEntity().getContent(), Charset.defaultCharset())).at(fieldPath);
}

private void updateFieldLimit() {
Expand Down

0 comments on commit 889025c

Please sign in to comment.