Calling getFieldsForWildcard from Indexpatternservice in a server side kibana plugin to refresh an index pattern

Hi,
I'm working on a plugin for kibana 7.9.1, at some point I'd like to refresh the fields of an index pattern. hence calling getFieldsForWildcard() of IndexPatternsApiClient would be nice. I've basically the same question than this posts :

I managed something that works based on https://discuss.elastic.co/t/update-index-patterns-automatically-programatically/129547/2 and fetch library :confused: I'm trying to make it right ^^ meanwhile I'd be happy share it if someone needs it.

Thanks

Things have changed a bit since the posts you linked to. You should be able to add the data plugin to your plugin's lists of dependencies. Then, you should be able to instantiate a new IndexPatternsFetcher class with the Elasticsearch client you receive in the context.core.elasticsearch.asCurrentUser (I believe). Could you let me know if that helps?

Thanks Lukas,
Indeed it helped. I use : context.core.savedObjects.client.find(options); to find the pattern id
then :

        const { callAsCurrentUser } = context.core.elasticsearch.legacy.client;
        const indexPatternsService = new IndexPatternsFetcher(callAsCurrentUser);
        const optionsData = {
            pattern: indexPattern,
            metaFields: ["_source", "_id", "_type", "_index", "_score"]
        }
        const fields = await indexPatternsService.getFieldsForWildcard(optionsData);
        const strFields = JSON.stringify(fields);
        const attributes = {
            "title": indexPattern,
            "fields": strFields
        };
        const updateResult = await context.core.savedObjects.client.update('index-pattern', patternId, attributes, {version: version});

But I'm not using data plugin I'm I? (I didn't add it the dependencies).
Is there an other way than using core.elasticsearch.legacy.client ?

Thanks anyway

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