elasticsearch,

Create an Elasticsearch Index Pattern using Kibana API

Apr 12, 2023 · 1 min read · Post a comment

Creating an Elasticsearch Index Pattern through Kibana API can be useful if don’t have direct Kibana access but you do have a remote instance that can access it. Let’s see how to create an index pattern through the instance console using the Kibana API.

Prerequisites

  • Elasticsearch
  • Kibana access
  • sudo privileges

Solution

  • To create an index pattern using the Kibana Saved Object API use the following curl call.
curl -X POST <kibana-host>:<port>/api/saved_objects/index-pattern/index-pattern-id -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d '
{
  "attributes": {
    "title": "my-index-*"
  }
}'
  • Here’s an example using some real values.
curl -X POST http://localhost:5601/api/saved_objects/index-pattern/my-pattern -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d '
{
  "attributes": {
    "title": "my-index-*"
  }
}'

This will create an index pattern with the ID my-pattern and a title of my-index-* on a Kibana instance running on localhost at port 5601.

  • As I mentioned the index pattern has a title of my-index-*. This means that it will match any indices in Elasticsearch whose names begin with my-index-. For example, indices with names such as my-index-1, my-index-2, my-index-2023, etc. will be matched by this index pattern.

Conclusion

Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.