Skip to content

Conversation

@ssunno
Copy link
Contributor

@ssunno ssunno commented Oct 2, 2025

Description

This PR add alias and data stream to return of ListIndicesTool.

The aliases and data streams are concepts that group multiple indices. But current version of ListIndicesTool does not support them, so it returns all indices equally, exposing the backing indices of data streams directly. To apply the intention of index designers, aliases and data streams should be returned as separate groups.

Note: Indices that belong to an alias or a data stream are excluded from the general index list to avoid duplication.

When include_detail = False, aliases and data streams return only the number of indices instead of their names.

example of ListIndicesTool (include_detail = False):

Indices, aliases, and data streams information:
{
  "indices": [
    "sonested",
    ".opendistro_security",
    ".opensearch-observability",
    ".plugins-ml-config"
  ],
  "aliases": [
    {
      "alias": "logs_current",
      "index_count": 2
    }
  ],
  "data_streams": [
    {
      "name": "logs-ds",
      "timestamp_field": {
        "name": "@timestamp"
      },
      "generation": 1,
      "status": "YELLOW",
      "template": "logs-template",
      "index_count": 1
    }
  ]
}

Issues Resolved

Resolves #56

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Sun Ro Lee <sunro.lee@linecorp.com>
@ssunno ssunno force-pushed the feat/listindextool-alias-ds branch from b18758f to 77912cc Compare October 2, 2025 15:18
Copy link
Collaborator

@rithin-pullela-aws rithin-pullela-aws left a comment

Choose a reason for hiding this comment

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

Thanks for raising the PR @ssunno, I believe this is a step in the right direction. Added few comments.

Comment on lines +22 to +24
if not isinstance(response, list):
logger.warning('Unexpected response type for cat.indices: %s', type(response))
return []
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the user is not authorized to perform the request, we might get an error response. This error should be propagated to the client making request in some form. But this would return an empty list

Comment on lines +48 to +50
if not isinstance(response, dict):
logger.warning('Unexpected response type for indices.get_alias: %s', type(response))
return {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above, should we handle it differently?

Comment on lines +77 to +79
if not isinstance(response, dict):
logger.warning('Unexpected response type for indices.get_data_stream: %s', type(response))
return []
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above

# List all the helper functions, these functions perform a single rest call to opensearch
# these functions will be used in tools folder to eventually write more complex tools
def list_indices(args: ListIndicesArgs) -> json:
def list_indices(args: ListIndicesArgs) -> list[dict]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit:
Would not block this PR, but something to perhaps think of

On a high level for list_indices, list_aliases, and list_data_streams

Would it make sense to create a class for the responses and parse the response into the classes? We can perhaps throw some sort of error if parsing fails. That way we can skip doing checks like isInstance etc?

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.

[FEATURE] Return alias and datastream in ListIndexTool

2 participants