Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: column aliases in cat indices API #1236

Conversation

larrycinnabar
Copy link
Contributor

@larrycinnabar larrycinnabar commented Nov 17, 2019

Feature: allow column (?h=) aliases in cat indices API

Why this should be part of the repo?

This repository allows to call any elastic request, so if elastic can execute http://localhost:9200/_cat/indices?h=idx, then this repo should too. (having idx instead of index)

Implementation

  • in cat_indices.go, when url is built - given columns are looked up in the alias map and replaced if any
  • an alias can be given to multiple original fields because of backwards compatibility (depending on which of 7.* version, you may have refresh.time or refresh.external_time, and they both have rti alias)
  • alias map is constructed on the init stage (using init() function). It uses reflect, but as it's one-time on-startup call, I consider this not harmful.
    Other option (to avoid reflect) is to manually declare the alias map. But this approach has a drawback as well: we declare fields in two places manually: the CatIndicesResponseRow struct and the aliases map. And when updating further, developer is required to update BOTH things, so it will become a danger place that can admit bugs when developer updates one thing and forgets about other.
  • Tests are added:
    • very simple test to check if alias map exists
    • test on ?h=h to be the same as ?h=health
    • test on double alias with ?h=rti

@larrycinnabar larrycinnabar changed the title feature: cat indices. aliases for columns feature: column aliases in cat indices API Nov 17, 2019
@larrycinnabar
Copy link
Contributor Author

@olivere any ideas, arguments, suggestions?

Copy link
Owner

@olivere olivere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a comment to simplify things a bit.

cat_indices.go Outdated Show resolved Hide resolved
@larrycinnabar larrycinnabar force-pushed the feature/cat-indices-columns-aliases branch from f89f5aa to 4d9535b Compare December 7, 2019 19:53
@larrycinnabar
Copy link
Contributor Author

larrycinnabar commented Dec 7, 2019

Upd: switched from alias reflect-generation to manual hard-coded map

Ready for merging

@olivere olivere merged commit 93c45de into olivere:release-branch.v7 Jan 4, 2020
@olivere
Copy link
Owner

olivere commented Jan 4, 2020

Thanks. Will be released in 7.0.10.

olivere added a commit that referenced this pull request Jan 4, 2020
This commit allows to specify aliases to the cat indices API,
in the same way that the `curl` command does when using
the `_cat/indices` endpoint.

See #1236
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants