7

I am trying to create an index_pattern for dashboard in Opensearch programmatically.

Due to the fact that I didn't found anything related to it on Opensearch documentation, I tried the elastic search saved_objects api:

POST /api/saved_objects/index-pattern/my_index_pattern
{
  "attributes":{
    "title": "my_index"
  }
}

But when I call it I got the following error:

{
  "error" : "no handler found for uri [/api/saved_objects/index-pattern/my_index_pattern?pretty=true] and method [POST]"
}

How can I solve it? Are there a different call for Opensearch to create an index_pattern?

Wolfetto
  • 1,030
  • 7
  • 16

1 Answers1

1
curl -k -X POST http://<host>:5601/api/saved_objects/index-pattern/logs-* -H "osd-xsrf:true" -H "content-type:application/json" -d '
{
  "attributes": {
    "title": "logs-*",
    "timeFieldName": "@timestamp"
   }
}'

this works for me

doge76
  • 21
  • 2
  • 1
    Yes, it works. But keep in mind that if you want the index-pattern to be global, you should also add this attribute in header: securitytenant: "global", – Vasi Maruseac Apr 14 '22 at 11:46
  • I don't know what you're running this command against but it's not OpenSearch 1.2 like the OP noted. Running this command against a host serving v1.2 will return `{"error":"no handler found for uri [/api/saved_objects/index-pattern/logs-*] and method [POST]"}`. – Resisty Dec 21 '22 at 22:36