In OpenSearch Version 2.12.0 , Snapshot Management curl is not working

Hi Team ,

As I’m using the Opensearch version 2.12.0 , When i tried to create the SM policy to take backup and create snapshot of my indices , I’m facing issue on my curl command , the command and error is given below -

curl -XPUT “http://localhost:9200/_plugins/_ism/policies/opensearch_sm_daily_backup” -H ‘Content-Type: application/json’ -d’
{
“description”: “opensearch_sm_daily_backup”,
“creation”: {
“schedule”: {
“cron”: {
“expression”: “5 * * * *”,
“timezone”: “UTC”
}
}
},
“snapshot_config”: {
“date_format”: “yyyy-MM-dd-HH:mm”,
“timezone”: “UTC”,
“indices”: “test”,
“repository”: “opensearch_sm_repo”,
“ignore_unavailable”: “true”,
“include_global_state”: “false”,
“partial”: “true”,
“metadata”: {
“any_key”: “any_value”
}
}
}’
{“error”:{“root_cause”:[{“type”:“parsing_exception”,“reason”:“Failed to parse object: expecting token of type [START_OBJECT] but found [VALUE_STRING]”,“line”:3,“col”:18}],“type”:“parsing_exception”,“reason”:“Failed to parse object: expecting token of type [START_OBJECT] but found [VALUE_STRING]”,“line”:3,“col”:18},“status”:400}

Same curl i used in the earlier version 1.3.14 opensearch , there is also same issue i faced , but found from the link that SM policy will only work in 2.X version or greater. That’s why i tried with version 2.12.0.

Anyone have any idea will helpful for me.

Thanks in Advance.

Hey @Dipanshu

Did you create a repository to hold your snapshots?

Yes i create the repository first after then i run this curl , if you see the repo name is also mentioned in the curl given below like -

“repository”: “opensearch_sm_repo”,

Hey @Dipanshu

Did you check Line 3 col 18 see what was wrong?

EDIT: I broke down your curl command error, I think this is where the issue is.

  • parsing_exception: Indicates that there was an error while parsing the data.

  • Failed to parse object: It couldn’t parse the data as an object.

  • expecting token of type [START_OBJECT] but found [VALUE_STRING]: It expected the beginning of an object ({) but found a string value instead. This suggests that the data might not be formatted correctly.

Give this a try, hope it helps.

curl -XPUT "http://localhost:9200/_plugins/_ism/policies/opensearch_sm_daily_backup" -H "Content-Type: application/json" -d '
{
  "description": "opensearch_sm_daily_backup",
  "creation": {
    "schedule": {
      "cron": {
        "expression": "5 * * * *",
        "timezone": "UTC"
      }
    }
  },
  "snapshot_config": {
    "date_format": "yyyy-MM-dd-HH:mm",
    "timezone": "UTC",
    "indices": "test",
    "repository": "opensearch_sm_repo",
    "ignore_unavailable": true,
    "include_global_state": false,
    "partial": true,
    "metadata": {
      "any_key": "any_value"
    }
  }
}'
  • Replaced the double quotation marks around the URL with single quotation marks.

  • Ensured that all keys and string values are enclosed in double quotation marks (") as per JSON standard.

  • Replaced the boolean values true and false without quotation marks.

  • Formatted the JSON data for better readability.