I am trying to wrap my head around Bleve and I understand everything that is going on in the tutorials, videos and documentation. I however get very confused when I am using it on BoltDB and don't know how to start.
Say I have an existing BoltDB database called data.db populated with values of struct type Person
type Person struct {
ID int `json:"id"`
Name string `json:"name"`
Age int `json:"age"`
Sex string `json:"sex"`
}
How do I index this data so that I can do a search? How do I handle the indexing of data that will be stored in the database in the future?
Any help will be highly appreciated.
Bleve uses BoltDB as one of several backend stores and is separate from where you store your application data. To index your data in Bleve, simply add your
Index:index.Index(person.ID, person)That
indexexists separately from your application data (whether it's in Bolt, Postgres, etc).To retrieve your data, you'll need to construct a search request using
bleve.NewSearchRequest(), then callIndex.Search(). This will return aSearchResultwhich includes aHitsfield where you can retrieve theIDfor your object. You can use this to look up the object in your application data store.Disclaimer: I am the author of BoltDB.