OpenSearch 1.2 - Index pattern programmatically
Asked Answered
R

2

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?

Ritzy answered 6/4, 2022 at 16:11 Comment(0)
C
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

Centaur answered 14/4, 2022 at 8:30 Comment(2)
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",Cosmetician
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]"}.Skywriting
P
0

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

Parenthesis answered 25/3 at 20:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.