2024-04-29 16:55:53 +02:00
|
|
|
#!/bin/bash
|
2024-05-16 12:33:48 +02:00
|
|
|
set -e
|
2024-04-29 16:55:53 +02:00
|
|
|
|
|
|
|
echo "Creating Elasticsearch indexes, roles, and users..."
|
|
|
|
|
|
|
|
# Command to create the "plans" index
|
2024-05-13 15:30:25 +02:00
|
|
|
curl -XPUT "http://localhost:9200/opencdmp-plans-test" -u elastic:elastic -H 'Content-Type: application/json' -d '{
|
2024-04-29 16:55:53 +02:00
|
|
|
"settings": {
|
|
|
|
"number_of_shards": 1,
|
|
|
|
"number_of_replicas": 1
|
|
|
|
},
|
|
|
|
"mappings": {
|
|
|
|
"properties": {
|
|
|
|
"title": { "type": "text" },
|
|
|
|
"description": { "type": "text" },
|
|
|
|
"price": { "type": "float" },
|
|
|
|
"date_added": { "type": "date" }
|
|
|
|
}
|
|
|
|
}
|
2024-05-16 12:33:48 +02:00
|
|
|
}' || { echo "Failed to create the 'plans' index"; exit 1; }
|
2024-04-29 16:55:53 +02:00
|
|
|
|
|
|
|
# Command to create the "descriptions" index
|
2024-05-13 15:30:25 +02:00
|
|
|
curl -XPUT "http://localhost:9200/opencdmp-descriptions-test" -u elastic:elastic -H 'Content-Type: application/json' -d '{
|
2024-04-29 16:55:53 +02:00
|
|
|
"settings": {
|
|
|
|
"number_of_shards": 1,
|
|
|
|
"number_of_replicas": 1
|
|
|
|
},
|
|
|
|
"mappings": {
|
|
|
|
"properties": {
|
|
|
|
"product_id": { "type": "keyword" },
|
|
|
|
"description_text": { "type": "text" },
|
|
|
|
"language": { "type": "keyword" }
|
|
|
|
}
|
|
|
|
}
|
2024-05-16 12:33:48 +02:00
|
|
|
}' || { echo "Failed to create the 'descriptions' index"; exit 1; }
|
2024-04-29 16:55:53 +02:00
|
|
|
|
2024-05-16 12:33:48 +02:00
|
|
|
# Command to create the role
|
2024-05-09 16:55:24 +02:00
|
|
|
curl -XPOST "localhost:9200/_security/role/opencdmp-api-test" -u elastic:elastic -H 'Content-Type: application/json' -d '{
|
2024-04-29 16:55:53 +02:00
|
|
|
"indices": [
|
|
|
|
{
|
2024-05-13 15:30:25 +02:00
|
|
|
"names": [ "opencdmp-plans-test", "opencdmp-descriptions-test" ],
|
2024-04-29 16:55:53 +02:00
|
|
|
"privileges": [ "all" ]
|
|
|
|
}
|
|
|
|
]
|
2024-05-16 12:33:48 +02:00
|
|
|
}' || { echo "Failed to create the role"; exit 1; }
|
2024-04-29 16:55:53 +02:00
|
|
|
|
2024-05-16 12:33:48 +02:00
|
|
|
# Command to create the user
|
|
|
|
curl -XPOST "localhost:9200/_security/user/opencdmp-api-test?pretty" -u elastic:elastic -H 'Content-Type: application/json' -d '
|
2024-04-29 16:55:53 +02:00
|
|
|
{
|
2024-05-13 15:30:25 +02:00
|
|
|
"password" : "opencdmp",
|
2024-05-09 16:55:24 +02:00
|
|
|
"roles" : [ "opencdmp-api-test" ]
|
2024-05-16 12:33:48 +02:00
|
|
|
}' || { echo "Failed to create the user"; exit 1; }
|
2024-05-13 15:30:25 +02:00
|
|
|
|
2024-05-16 12:33:48 +02:00
|
|
|
# Install the analysis-icu plugin
|
|
|
|
elasticsearch-plugin install analysis-icu || { echo "Failed to install the analysis-icu plugin"; exit 1; }
|
|
|
|
|
|
|
|
echo "Initialization complete."
|