Wolfetto
Wolfetto

Reputation: 1130

OpenSearch 1.2 - Index pattern programmatically

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?

Upvotes: 7

Views: 3590

Answers (2)

Prashanth Dudipala
Prashanth Dudipala

Reputation: 1

Thanks to the blog here: https://repost.aws/knowledge-center/opensearch-index-pattern

Run the following curl command to generate authorization cookies into the auth.txt file:

curl -X POST  https://opensearch-end-point/_dashboards/auth/login  \
     -H "osd-xsrf: true" \
     -H "content-type: application/json" \
     -d '{"username":"<username>", "password":"<password>"}' \
     -c auth.txt

Then, submit the index pattern creation request:

curl -X POST  https://opensearch-end-point/_dashboards/api/saved_objects/index-pattern/  \
     -H "osd-xsrf: true" \
     -H "content-type: application/json" \
     -d '{ "attributes": { "title": "sample-index*" } }' \
     -b auth.txt

worked for me

Upvotes: 0

doge76
doge76

Reputation: 21

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

Upvotes: 1

Related Questions