Created
March 3, 2021 21:45
-
-
Save mschoch/38ca2f678515dd6abe6c48c2f6cfd2cd to your computer and use it in GitHub Desktop.
A utility function to force merge a Bleve index into a single segment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func forceMerge(index bleve.Index) error { | |
internalIndex, err := index.Advanced() | |
if err != nil { | |
return fmt.Errorf("unable to access internal index: %v", err) | |
} | |
if scorchIndex, ok := internalIndex.(*scorch.Scorch); ok { | |
numFiles := scorchIndex.StatsMap()["num_files_on_disk"].(uint64) | |
for numFiles > 2 { | |
err = scorchIndex.ForceMerge(context.Background(), nil) | |
if err != nil { | |
return err | |
} | |
numFiles = scorchIndex.StatsMap()["num_files_on_disk"].(uint64) | |
} | |
return nil | |
} | |
return fmt.Errorf("this index does not support merge") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment