Create index patterns / saved objects in plugin

Is it possible to create index patterns with the help of Elasticsearch JS client in Elkstack 7.3+?
Or, for example, from Kibana plugin?

I know it's possible from the API side, but is it achievable using the client?

Thanks a lot

Yes, it's possible to use SavedObject client for this, but with nuances. If you don't have a lot of the logic on the server it would be easier to call API endpoint directly.
Operations with SavedObjects performed on behalf of a user. It means that whenever you access SavedObject client on the server, it should be associated with the incoming request objects. Thus you need to register your endpoint to get SavedObjects client and create index-pattern:

const client  = request.getSavedObjectsClient();
client.create('index-pattern', ...);

example from the Kibana codebase:

1 Like

Thanks for the answer.

And is anything available from the server side to do similar things? (getting and creating index patterns)

I think we use saved object interface for this. as in example before: savedObjectsClient.create('index-pattern', ...)

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.