Fix elasticsearch v8 cluster_settings unmarshal error #915
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #840
For example, the result of calling the
_cluster/settings
API on an off-the-shelf Elasticsearch might look like the following.When a custom setting related to
cluster.routing.allocation.watermark.flood_stage
is introduced intransient
, the output changes as follows.As can be seen from this example, the JSON returned by the Elasticsearch
_cluster/settings
API is not uniform. Therefore, workarounds are necessary to unmarshal it into Go structures. This issue is also pointed out in #509.This PR addresses the above issue in a general way. When unmarshalling JSON into Go structures, the JSON is converted into a flattened format. The flattened map (i.e., key-value pairs) is then remapped to Go structures using mitchellh/mapstructure. By doing this, it ensures that even non-uniform JSON can be unmarshalled reliably.