I have a docker-compose file containing opensearch:2.7 and opensearch-dashboards:2.7
services:
opensearch:
image: opensearchproject/opensearch
opensearch-dashboards:
image: opensearchproject/opensearch-dashboards
ports:
- published: 8094
target: 5601
I would like for the opensearch dashboard to configure an index pattern on startup.
I noticed that the UI will allow me to export my index pattern.
And then import that index pattern later.
Using the UI, I can successfully re-create the index-patter.
Is there a way to perform this import via docker-compose?
curl -X POST \
-H "osd-xsrf: true" \
"http://admin:admin@localhost:8094/api/saved_objects/_import?overwrite=true" \
--form file=@data/export.ndjson
The action appears to work. Unfortunately, this does not create a saved object or an index pattern.
{"successCount":1,"success":true,"successResults":[{"type":"index-pattern","id":"62df61e0-ea0b-11ed-b0ee-5f4ec07e6377","meta":{"title":"ecs*","icon":"indexPatternApp"},"overwrite":true}]}
The post I referenced above helped me to solve this issue.
services:
opensearch:
image: opensearchproject/opensearch
opensearch-dashboards:
image: opensearchproject/opensearch-dashboards
ports:
- published: 8094
target: 5601
init:
image: curlimages/curl
container_name: init
environment:
- DOMAIN=my.domain
entrypoint:
- /bin/sh
- '-c'
- |
URL=http://admin:admin@$HOSTNAME.$$DOMAIN:8094
status_code=$$(curl --write-out %{http_code} --silent --output /dev/null $$URL/app/home)
echo $$status_code
sleep 2
while [ $$status_code -ne 200 ]
do
status_code=$$(curl --write-out %{http_code} --silent --output /dev/null $$URL/app/home)
echo $$status_code
sleep 2
done
cat > /tmp/indexpattern.json << HERE
{
"attributes": {
"title": "ecs-*",
"timeFieldName": "@timestamp"
}
}
HERE
curl --silent -H "osd-xsrf: true" \
-H "Content-Type: application/json" \
-H "securitytenant: Global" \
-d "@/tmp/indexpattern.json" \
"$URL/api/saved_objects/index-pattern/ecs-*"
echo 'index pattern imported'
depends_on:
- opensearch
- opensearch-dashboards