Skip to content

Instantly share code, notes, and snippets.

@grahamwhaley
Last active August 16, 2019 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grahamwhaley/8eae5844ad59e4aa43b26e61c9511fb4 to your computer and use it in GitHub Desktop.
Save grahamwhaley/8eae5844ad59e4aa43b26e61c9511fb4 to your computer and use it in GitHub Desktop.
Duplicate an elasticsearch index with logstash

I wanted to copy an index in my elasticsearch DB, so I could try and re-open it in Kibana whilst ticking the 'not a time series database' option. So, how to copy an index??

I found a useful post at http://david.pilato.fr/blog/2015/05/20/reindex-elasticsearch-with-logstash/ That copies an index from one elastic to another, and is written for an older version of logstash. Updating that to logstash ~7.3 and modifying to copy an index to a new index of a different name in the same DB, I came up with:

# Logstash config to copy one index to another

input {
  # We read from the "old" cluster
  elasticsearch {
    hosts => "192.168.0.111:9200" 
    index => "logtest"
    size => 500
    scroll => "5m"
    docinfo => true
  }
}

output {
  # We write to the "new" cluster
  elasticsearch {
    hosts => "192.168.0.111:9200"
    index => "test"
    document_id => "%{[@metadata][_id]}"
  }
  # We print dots to see it in action
  stdout {
    codec => "dots"
  }
}

and to invoke it:

#!/bin/bash

set -x

sudo /usr/share/logstash/bin/logstash -f copy.conf

I can see a copy - now, to check if I have data!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment