Index Aliases
Bleve has a powerful feature called an IndexAlias
. The IndexAlias can be used to search an index, with the additional ability to atomically switch the underlying physical index. IndexAliases can also be search to search across multiple indexes at the same time and correctly merge the results.
IndexAlias Interface
First, its useful to note that thanks to Go interfaces, an IndexAlias is also an Index. This means that in general you work with an IndexAlias just as you would work with an Index. The alias concept also adds 3 methods: Add(), Remove(), and Swap()
Add, will add one or more indexes to the alias. Remove will remove one or more indexes from the alias. Swap will atomically add/remove the provided indexes. (all other ops, like search will see the alias before or after all adds/removes are done)
Switching Indexes with Zero Downtime
- Create a new Index
- Create an IndexAlias pointing to the Index
- Write your application to query the IndexAlias
- …At some later time, create a new Index
- Call Swap() on the IndexAlias passing in the new Index
Your application will safely switch to searching the new index.
Searching Across Multiple Indexes
- Create more than one Index
- Create the IndexAlias pointing to these indexes
- Writer your application to invoke Search() on the IndexAlias
Your application will search across all the underlying indexes at the same time, and the results will be merged together into a single result.
Limitations
When and IndexAlias points to multiple indexes not all operations are supported. Only operations which can be invoked on all the child indexes and have their responses aggregated are supported. Operations that are not supported return bleve.ErrorAliasMulti
.