Skip to content

Commit

Permalink
Allow for ES index names to be customized per env
Browse files Browse the repository at this point in the history
  • Loading branch information
thatandromeda committed Mar 7, 2019
1 parent 97901be commit 2c943c2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
3 changes: 2 additions & 1 deletion app/models/entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class Entity < ActiveRecord::Base

index_name [Rails.application.engine_name,
Rails.env,
self.name.demodulize.downcase].join('_')
name.demodulize.downcase,
ENV['ES_INDEX_SUFFIX']].compact.join('_')

def as_indexed_json(_options)
out = as_json
Expand Down
5 changes: 4 additions & 1 deletion app/models/searchability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ def self.included(base)

module ClassMethods
def define_elasticsearch_mapping(exclusions = {})
index_name [Rails.application.engine_name, Rails.env, 'notice'].join('_')
index_name [Rails.application.engine_name,
Rails.env,
'notice',
ENV['ES_INDEX_SUFFIX']].compact.join('_')
document_type 'notice'

settings do
Expand Down
15 changes: 9 additions & 6 deletions doc/ELASTICSEARCH_INDEXING.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
Elasticsearch Indexing
======================
# Elasticsearch Indexing

Incremental
===========
## Incremental

Elasticsearch indexing happens out-of-process, meaning you must keep the index
up to date by periodically running `ReindexRun.index_changed_model_instances`.
Expand All @@ -24,8 +22,7 @@ timing information that you can parse by comparing the `updated_at` and
You should ensure that no more than one of the incremental indexers tasks is
running at once via a `lockrun`-like cron harness.

Recreating the elasticsearch index
==================================
## Recreating the elasticsearch index

You can either remove all ReindexRun rows, or - preferably - use the
`lumen::recreate_elasticsearch_index` rake task after disabling the
Expand All @@ -38,3 +35,9 @@ It should only be necessary to recreate the elasticsearch index when:
* There's a problem with elasticsearch and you've got a corrupted index
* You change the index mapping
* You're setting things up for the first time

## Customizing the index names

`app/models/entity.rb` and `app/models/searchability.rb` define the index names for `Entity` and `Notice` respectively. You do not need to do anything about this.

However, if you would like to customize index names (e.g. to allow for multiple instances or zero-downtime upgrades), you can set the environment variable `ES_INDEX_SUFFIX`. Your specified string will be added to the end of the index name.

0 comments on commit 2c943c2

Please sign in to comment.