Skip to content

Instantly share code, notes, and snippets.

@tankhuu
Last active September 22, 2017 07:38
Show Gist options
  • Save tankhuu/a29a429f4364b864f95b74f57e005ccb to your computer and use it in GitHub Desktop.
Save tankhuu/a29a429f4364b864f95b74f57e005ccb to your computer and use it in GitHub Desktop.
Elasticsearch - Tips
PUT _snapshot/s3_repo
{
"type": "s3",
"settings": {
"bucket": "bucket_name",
"base_path": "elasticsearch/snapshots"
}
}
GET /_snapshot/s3_repo
# Remember, leave a key empty if there is no value. None will be a string,
# not a Python "NoneType"
#
# Also remember that all examples have 'disable_action' set to True. If you
# want to use this action as a template, be sure to set this to False after
# copying it.
actions:
1:
action: snapshot
description: >-
Snapshot mysql-slow- prefixed indices older than 1 month (based on index
name) with the default snapshot name pattern of
'mysql-slow-%Y%m%d%H%M%S'. Wait for the snapshot to complete.
Use the other options to create the snapshot.
options:
repository: s3_repo
# Leaving name blank will result in the default 'curator-%Y%m%d%H%M%S'
name:
ignore_unavailable: False
include_global_state: True
partial: False
wait_for_completion: True
skip_repo_fs_check: True
disable_action: False
filters:
- filtertype: pattern
kind: prefix
value: mysql-slow-
- filtertype: age
source: name
direction: older
timestring: '%Y.%m.%d'
unit: days
unit_count: 30
POST _reindex
{
"size": 10,
"source": {
"index": "icare_stage_product"
},
"dest": {
"index": "icare_stage_product_20170922"
},
"script": {
"inline": "if(ctx._source.price == null) {ctx._source.price = 0} else {Long price = Long.parseLong(ctx._source.price);ctx._source.price = price}",
"lang": "painless"
}
}
# Create S3 bucket & IAM user with the right Policy
# (https://www.elastic.co/guide/en/elasticsearch/plugins/current/repository-s3.html)
sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install repository-s3
echo "# AWS S3" | sudo tee -a /etc/elasticsearch/elasticsearch.yml
echo "cloud.aws.s3.access_key: AWS_ACCESS_KEY" | sudo tee -a /etc/elasticsearch/elasticsearch.yml
echo "cloud.aws.s3.secret_key: AWS_SECRET_KEY" | sudo tee -a /etc/elasticsearch/elasticsearch.yml
echo "cloud.aws.s3.region: BUCKET_REGION" | sudo tee -a /etc/elasticsearch/elasticsearch.yml
sudo service elasticsearch restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment