What is the method to create Index Pattern in Python

Hello, All

In Python, I use let say "es.indices.put_index_template()" method to create Index Template, "es.indices.create()" to create index but what method should be used to create Index Pattern ?

By index pattern you mean the pattern to use in Kibana? I don't think that there is a method for it in the elasticsearc python API.

You only need to create an index pattern when using Kibana, when interacting with Elasticsearch using the python library there is no need for it.

It can be confusing because there is Elasticsearch index pattern and kibana index pattern, they are similar, but not the same thing.

The Elasticsearch index pattern is just a the pattern used when making requests to Elasticsearch for some index, like index-name-* will tell Elasticsearch that you want to make requests to every index that starts with index-name-, this is also used in the index templates.

The kibana index pattern does a similar thing, but for Kibana, it also creates an internal object that is used in visualizations and dashboards to make references to the index that match the index pattern.

There is an experimental Kibana API to create kibana index patterns.

Screenshot 2021-11-14 at 09.12.55

Yes, I meant Kibana Index Pattern, well I checked that link, but I wonder is there any way to send the request via method ? maybe there is need to import other package to obtain that method ?
Generally, if that method even exists somehow ?

query = 
"settings": {
        "number_of_shards": 2,
        "number_of_replicas": 1,
        "mappings": {...},
        "index-pattern" : {
            "title" : "myindex",
            "timeFieldName" : "sendTime",
            "fields" : """[{"name":"_id","type":"string","esTypes":["_id"],"count":0, ...]}"""

es_client.indices.create(index = "myindex" , body = query)

I found this code in stackoverflow, can you check if it can be used to ?

There is no such method, Kibana Index Pattern needs to be created on Kibana or using the Kibana API, the Elasticsearch python library has no method to interact with Kibana as it is a completely different tool with a different set of APIs, you do not need Kibana to use Elasticsearch, so it makes no sense for the Elasticsearch API to interact with Kibana.

There is not a Kibana package as a lot of Kibana API are still experimental, maybe in the future there will be a Kibana Python package, but at this moment you will need to create the index pattern using the Kibana UI or using the experimental API.

You can build a custom method in your python script to do that if you want.

Also, I don't think the code you shared will work, the payload is wrong and makes no sense as you have mappings inside settings, and there is no index-pattern setting.

Understood, Thank you for comprehensive explanation. The topic can be closed.

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