# Create index patterns / saved objects in plugin

**URL:** <https://discuss.elastic.co/t/create-index-patterns-saved-objects-in-plugin/203488>\
**Category:** Kibana\
**Created:** [October 14, 2019, 4:12pm UTC](https://discuss.elastic.co/t/create-index-patterns-saved-objects-in-plugin/203488 "2019-10-14T16:12:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![arseni-lipinski](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@arseni-lipinski](https://discuss.elastic.co/u/arseni-lipinski)\
**Post date:** [October 14, 2019, 4:12pm UTC](https://discuss.elastic.co/t/create-index-patterns-saved-objects-in-plugin/203488/1 "2019-10-14T16:12:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Mikhail\_Shustov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mikhail_shustov/32/49186_2.png) [@Mikhail\_Shustov](https://discuss.elastic.co/u/Mikhail_Shustov)\
**Post date:** [October 15, 2019, 11:39am UTC](https://discuss.elastic.co/t/create-index-patterns-saved-objects-in-plugin/203488/2 "2019-10-15T11:39:16Z")

</div>

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

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

```

example from the Kibana codebase:

> <https://github.com/elastic/kibana/blob/92917c1c19040c47daca3be10b280ce08d96a135/src/legacy/server/saved_objects/routes/create.ts#L82>

---

<div class="post-metadata">

**Author:** ![arseni-lipinski](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@arseni-lipinski](https://discuss.elastic.co/u/arseni-lipinski)\
**Post date:** [October 15, 2019, 5:38pm UTC](https://discuss.elastic.co/t/create-index-patterns-saved-objects-in-plugin/203488/3 "2019-10-15T17:38:30Z")

</div>

Thanks for the answer.

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

---

<div class="post-metadata">

**Author:** ![Mikhail\_Shustov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mikhail_shustov/32/49186_2.png) [@Mikhail\_Shustov](https://discuss.elastic.co/u/Mikhail_Shustov)\
**Post date:** [October 18, 2019, 4:47pm UTC](https://discuss.elastic.co/t/create-index-patterns-saved-objects-in-plugin/203488/4 "2019-10-18T16:47:55Z")

</div>

> [@arseni-lipinski](#):
>
> 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', ...)`

---

<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:** [November 15, 2019, 4:48pm UTC](https://discuss.elastic.co/t/create-index-patterns-saved-objects-in-plugin/203488/5 "2019-11-15T16:48:01Z")

</div>

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