diff --git a/docs/ansible/wiki/elk/introduction.md b/docs/ansible/wiki/elk/introduction.md index 40b8c6fe7a371700727ad1e7cb9363ab4d557a18..7f2c0f72573f736a5ae2f57e8a44a4315b7a53a3 100644 --- a/docs/ansible/wiki/elk/introduction.md +++ b/docs/ansible/wiki/elk/introduction.md @@ -5,10 +5,10 @@ tags: --- # ElasticSearch -- [Introduction](elk/introduction) -- [Collecting Data](elk/fluentd) -- [UI to view the data](elk/kibana) -- [Alerts on Log Data](monitoring/alerts-elk) +- [Collecting Data](fluentd) +- [UI to view the data](kibana) +- [Alerts on Log Data](../monitoring/alerts-elk) +- [Re-Indexing a broken index](re-indexing) Log data from the OS and selected applications is generated on the server farm on many different places and we are aggregating all of that data in ElasticSearch so that we can analyse the systems when ever needed but also to be able to raise alerts if something is going wrong. diff --git a/docs/ansible/wiki/elk/re-indexing.md b/docs/ansible/wiki/elk/re-indexing.md new file mode 100644 index 0000000000000000000000000000000000000000..507a46775af5e02f616bf291177b99da0e3cdc15 --- /dev/null +++ b/docs/ansible/wiki/elk/re-indexing.md @@ -0,0 +1,84 @@ +--- +title: Ansible Wiki ELK Re-Indexing +tags: +- ansible +--- +# Re-index ElasticSearch Index + +Sometimes an index gets broken and here is how this can be repaired following +this [great guide](https://www.thirdrocktechkno.com/blog/6-steps-to-reindex-elasticsearch-data) + +We use `$IDX` for the existing, e.g. broken index and `$IDXNEW` for the new one. + +## Show number of records for all indexes + +```shell +curl -X GET 'http://${ELUSER}:${ELPASS}@localhost:9200//_cat/indices/%2A?v=&s=index:desc' +``` + +## Create new index with mappings + +```shell +curl -X PUT http://${ELUSER}:${ELPASS}@localhost:9200/$IDXNEW \ + -H 'Content-Type: application/json' \ + -d '{ + "mappings": { + "properties": { + [PROVIDE THE MAPPING HERE] + } + } + }' +``` + +## Re-index from old to new index + +```shell +curl -X POST http://${ELUSER}:${ELPASS}@localhost:9200/_reindex \ + -H 'Content-Type: application/json' \ + -d '{ + "source": { + "index": "$IDX" + }, + "dest": { + "index": "$IDXBEW" + } + }' +``` + +## Delete the old index + +```shell +curl -X DELETE http://${ELUSER}:${ELPASS}@localhost:9200/$IDX +``` + +## Delete and recreate alias + +```shell +curl -X POST http://${ELUSER}:${ELPASS}@localhost:9200/_aliases \ + -H 'Content-Type: application/json' \ + -d '{ + "actions": [ + { + "remove": { + "index": "$IDXNEW", + "alias": "$IDX" + } + } + ] + }' +``` + +```shell +curl -X POST http://${ELUSER}:${ELPASS}@localhost:9200/_aliases \ + -H 'Content-Type: application/json' \ + -d '{ + "actions": [ + { + "add": { + "index": "$IDXNEW", + "alias": "$IDX" + } + } + ] + }' +```