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

**URL:** <https://discuss.elastic.co/t/calling-getfieldsforwildcard-from-indexpatternservice-in-a-server-side-kibana-plugin-to-refresh-an-index-pattern/258296>\
**Category:** Kibana\
**Tags:** kibana-plugin-development\
**Created:** [December 10, 2020, 3:05pm UTC](https://discuss.elastic.co/t/calling-getfieldsforwildcard-from-indexpatternservice-in-a-server-side-kibana-plugin-to-refresh-an-index-pattern/258296 "2020-12-10T15:05:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aadrien](https://avatars.discourse-cdn.com/v4/letter/a/96bed5/32.png) [@Aadrien](https://discuss.elastic.co/u/Aadrien)\
**Post date:** [December 10, 2020, 3:05pm UTC](https://discuss.elastic.co/t/calling-getfieldsforwildcard-from-indexpatternservice-in-a-server-side-kibana-plugin-to-refresh-an-index-pattern/258296/1 "2020-12-10T15:05:53Z")

</div>

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 :

- [https://discuss.elastic.co/t/how-to-check-that-index-pattern-is-not-synced-with-mapping-using-kibana-plugin/183723/2](https://discuss.elastic.co/t/how-to-check-that-index-pattern-is-not-synced-with-mapping-using-kibana-plugin/183723/2) but I don't have the server object (routes are defined with router: IRouter)
- [https://discuss.elastic.co/t/how-to-get-use-indexpatternservice-in-server-side-api-in-kibana-plugin/186531](https://discuss.elastic.co/t/how-to-get-use-indexpatternservice-in-server-side-api-in-kibana-plugin/186531) :  
Any news since kibana 6?

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

Thanks

---

<div class="post-metadata">

**Author:** ![lukas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas/32/6812_2.png) [@lukas](https://discuss.elastic.co/u/lukas)\
**Post date:** [December 10, 2020, 5:17pm UTC](https://discuss.elastic.co/t/calling-getfieldsforwildcard-from-indexpatternservice-in-a-server-side-kibana-plugin-to-refresh-an-index-pattern/258296/2 "2020-12-10T17:17:29Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Aadrien](https://avatars.discourse-cdn.com/v4/letter/a/96bed5/32.png) [@Aadrien](https://discuss.elastic.co/u/Aadrien)\
**Post date:** [December 11, 2020, 12:46pm UTC](https://discuss.elastic.co/t/calling-getfieldsforwildcard-from-indexpatternservice-in-a-server-side-kibana-plugin-to-refresh-an-index-pattern/258296/3 "2020-12-11T12:46:25Z")

</div>

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

```auto
        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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 8, 2021, 12:46pm UTC](https://discuss.elastic.co/t/calling-getfieldsforwildcard-from-indexpatternservice-in-a-server-side-kibana-plugin-to-refresh-an-index-pattern/258296/4 "2021-01-08T12:46:27Z")

</div>

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