Skip to content

Instantly share code, notes, and snippets.

@mschoch
Created March 3, 2021 21:45
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 mschoch/38ca2f678515dd6abe6c48c2f6cfd2cd to your computer and use it in GitHub Desktop.
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
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