Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added initial ES configuration. #1

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM docker.elastic.co/elasticsearch/elasticsearch:8.9.0

# Simple, single node deployment
ENV discovery.type=single-node
ENV ES_JAVA_OPTS="-Xms512m -Xmx512m"
ENV xpack.security.enabled=false

# VIVO index name
ENV INDEX_NAME="vivo"

# Default es username
ENV ES_USERNAME="elastic"

EXPOSE 9200 9300

COPY setup-index.sh /tmp/setup-index.sh
COPY index-config.json /tmp/index-config.json

COPY setup-index.sh /usr/share/elasticsearch/setup-index.sh
COPY index-config.json /usr/share/elasticsearch/index-config.json

CMD ["sh", "-c", "/usr/local/bin/docker-entrypoint.sh & sleep 15 && sh /usr/share/elasticsearch/setup-index.sh && wait"]
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,41 @@
# vivo-es
Configuration for ElasticSearch index used by VIVO

# How to setup?

## Build the Docker Image:

```
docker build -t vivo-elasticsearch .
```

## Run the Container:

```
docker run -p 9200:9200 -p 9300:9300 --name vivo_es vivo-elasticsearch
```

This setup will start Elasticsearch, expose it on localhost:9200, and create the vivo index with the specified mapping by loading the configuration from index-config.json.

## Alternatively - Run Elasticsearch locally

1. Download Elasticsearch (suited for your platform) from the [official website](https://www.elastic.co/downloads/elasticsearch).
2. Run `bin/elasticsearch` (or `bin\elasticsearch.bat` on Windows) to start Elasticsearch [with security enabled](https://www.elastic.co/guide/en/elasticsearch/reference/current/configuring-stack-security.html).
3. Create `vivo` index by running:
ivanmrsulja marked this conversation as resolved.
Show resolved Hide resolved

```
curl -k -u <ES_USERNAME>:<ES_PASSWORD> -X PUT "https://localhost:9200/vivo" -H 'Content-Type: application/json' -d index-config.json
```

# Adding security
By default, this configuration sets up Elasticsearch without any security measures. A configuration like that is only viable if you are running your ES instance inside of an internal local-area network without exposing it to the internet. If you need to expose your ES instance to the internet you MUST activate necessary security mesures.

In order to setup security (SSL + basic authentication) you have to do the following steps:

- Comment-out or remove the following line from the Dockerfile `ENV xpack.security.enabled=false`

- Build the image and run the container as explained above

- Upon startup, the script will generate a new secure password for you to use when connecting to ES instance. Keep in mind that, at this moment, VIVO only supports basic authentication for ES (API key authentication will be added in the future). Find the console output that looks like this: `The new password for the elastic user is: <PASSWORD_VALUE>` and save the password value, you cannot access it later.

- Then, simply use your new password (username is always `elastic`) to connect to your ES instance from VIVO application.
107 changes: 107 additions & 0 deletions index-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{
"settings": {
"index": {
"analysis": {
"analyzer": {
"default": {
"type": "english"
}
}
}
}
},
"mappings": {
"dynamic_templates": [
{
"field_sort_template": {
"match": "*_label_sort",
"mapping": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
},
"fielddata": true
}
}
},
{
"field_ss_template": {
"match": "*_ss",
"mapping": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
},
"fielddata": true
}
}
},
{
"date_range_template": {
"match": "*_drsim",
"mapping": {
"type": "date_range",
"format": "strict_date_optional_time||epoch_millis"
}
}
}
],
"properties": {
"ALLTEXT": {
"type": "text",
"analyzer": "english",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"ALLTEXTUNSTEMMED": {
"type": "text",
"analyzer": "standard"
},
"DocId": {
"type": "keyword"
},
"classgroup": {
"type": "keyword"
},
"type": {
"type": "keyword"
},
"mostSpecificTypeURIs": {
"type": "keyword"
},
"indexedTime": {
"type": "long"
},
"nameRaw": {
"type": "keyword"
},
"URI": {
"type": "keyword"
},
"THUMBNAIL": {
"type": "integer"
},
"THUMBNAIL_URL": {
"type": "keyword"
},
"nameLowercaseSingleValued": {
"type": "text",
"analyzer": "standard",
"fielddata": true
},
"BETA": {
"type": "float"
}
}
}
}

48 changes: 48 additions & 0 deletions setup-index.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash


if [ -f /usr/share/elasticsearch/setup_done.flag ]; then
echo "Setup has already been completed, skipping setup."
exit 0
fi


SSL_ENABLED=$(curl -sk -X GET "https://localhost:9200")

if [ -z "$SSL_ENABLED" ]; then
echo "SSL not enabled, falling back to HTTP..."
SSL_ENABLED="false"
else
SSL_ENABLED="true"
echo "SSL is enabled"
fi

if [ "$SSL_ENABLED" == "true" ]; then
ES_URL="https://localhost:9200"
else
ES_URL="http://localhost:9200"
fi


ES_PASSWORD=$( /usr/share/elasticsearch/bin/elasticsearch-reset-password -u $ES_USERNAME --url $ES_URL --batch 2>&1 | grep -oP '(?<=New value: ).*' )

echo "The new password for the [$ES_USERNAME] user is: $ES_PASSWORD"


AUTH=""
if [[ -n "$ES_USERNAME" && -n "$ES_PASSWORD" ]]; then
AUTH="-u $ES_USERNAME:$ES_PASSWORD"
fi


until curl -k -s $AUTH -X GET "$ES_URL"; do
echo "Waiting for Elasticsearch to start..."
sleep 5
done

echo "Elasticsearch is up..."


curl -k $AUTH -X PUT "$ES_URL/$INDEX_NAME" -H 'Content-Type: application/json' -d @/usr/share/elasticsearch/index-config.json

touch /usr/share/elasticsearch/setup_done.flag