Skip to content

Commit

Permalink
[Console] Add autocompletion for data streams (elastic#198507)
Browse files Browse the repository at this point in the history
Closes elastic#190137

## Summary

This PR adds Console autocompletion for data streams.

We use the patterns in the spec definitions to determine what
autocomplete entity we should return. For example the `{index}` pattern
in the endpoint means we should suggest indices and aliases. This
pattern comes directly from the schema in the [Elasticsearch
specification
repo](https://github.com/elastic/elasticsearch-specification/blob/main/output/schema/schema.json),
which is used to generate the Console spec definition.

Previously, for the pattern `{index}`, we would only suggest indices and
aliases. However, for most of the endpoints where this pattern is used,
we should suggest indices, aliases, **and data streams** (see the table
below). For example, the [Get Index
API](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-index.html)
accepts indices, aliases, and data streams as the target, while the spec
definition for the `GET /<target>` endpoint uses the `{index}` pattern.

In this PR, we make Console also suggest data streams for the `{index}`
pattern.

List with some endpoints that use the `{index}` pattern:

Es API | Endpoint (with link to specs) | Expected target by Es
(according to docs) | Data stream compatible?
--- | --- | --- | --- 
[Get index
API](https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-index.html)
| [`GET
/<target>`](https://github.com/elastic/kibana/blob/e0838147bddeee43edbcb83ced8d0346f917047c/src/plugins/console/server/lib/spec_definitions/json/generated/indices.get.json#L35)
| data streams, indices, and aliases | ✅
[Async
Search](https://www.elastic.co/guide/en/elasticsearch/reference/current/async-search.html)
| [`POST
{index}/_async_search`](https://github.com/elastic/kibana/blob/e0838147bddeee43edbcb83ced8d0346f917047c/src/plugins/console/server/lib/spec_definitions/json/generated/async_search.submit.json#L94)
| Not specified | ✅ (tested locally)
[Index
API](https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html)
| `PUT/POST {index}/_create/{id}` | data stream or index | ✅
[Bulk
API](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html)
| [`POST/PUT
{index}/_bulk`](https://github.com/elastic/kibana/blob/3ac902df8a93d4924996c5cd1584faeeff9be6cb/src/plugins/console/server/lib/spec_definitions/json/generated/bulk.json#L36)
| data stream, index, or index alias | ✅
[cat count
API](https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-count.html)
| [`GET
_cat/count/{index}`](https://github.com/elastic/kibana/blob/3ac902df8a93d4924996c5cd1584faeeff9be6cb/src/plugins/console/server/lib/spec_definitions/json/generated/cat.count.json#L27)
| data streams, indices, and aliases | ✅
[cat indices
API](https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-indices.html)
| `GET _cat/indices/{index}` | data streams, indices, and aliases | ✅
[cat recovery
API](https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-recovery.html)
| `GET _cat/recovery/{index}` | data streams, indices, and aliases | ✅


Note: As discussed with @elastic/devtools-team, it is safe to assume
that endpoints with the `{index}` pattern accept data streams, apart
from indices and aliases. There are still a few edge cases though, such
as alias APIs, which don't accept data streams. Temporarily, it's okay
to display data stream suggestions for them, but we could try fixing
this in a follow-up PR by utilizing the override specs and adding a
pattern for indices and aliases only. Issue:
elastic#198588
  • Loading branch information
ElenaStoeva authored Nov 8, 2024
1 parent 8e7fb7a commit af2834f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/plugins/console/public/services/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ export class AutocompleteInfo {
case ENTITIES.INDICES:
const includeAliases = true;
const collaborator = this.mapping;
return () => this.alias.getIndices(includeAliases, collaborator);
return () => [
...this.alias.getIndices(includeAliases, collaborator),
...this.dataStream.getDataStreams(),
];
case ENTITIES.FIELDS:
return this.mapping.getMappings(
context.indices,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ const getAliases = async (settings: SettingsToRetrieve, esClient: IScopedCluster

const getDataStreams = async (settings: SettingsToRetrieve, esClient: IScopedClusterClient) => {
if (settings.dataStreams) {
const dataStreams = await esClient.asCurrentUser.indices.getDataStream();
const dataStreams = await esClient.asCurrentUser.indices.getDataStream({
name: '*',
expand_wildcards: 'all',
});
return dataStreams;
}
// If the user doesn't want autocomplete suggestions, then clear any that exist.
Expand Down

0 comments on commit af2834f

Please sign in to comment.