blevesearch/bleve
A modern text/numeric/geo-spatial/vector indexing library for go
What is bleve?
bleve is a search library written in the Go programming language. It lets developers add full-text search to their applications by indexing data (organizing it for fast retrieval) and then querying that index (searching it).
It can index any Go data structure or JSON data, and it ships with sensible defaults that you can customize if needed.
Core capabilities
Field types it can index
bleve understands many kinds of data fields:
- text (words/sentences)
- number (numeric values)
- datetime (dates and times)
- boolean (true/false)
- geopoint and geoshape (locations and areas on a map)
- IP (internet addresses)
- vector (mathematical representations used for similarity search)
Query types it supports
You can search using:
- Basic matches: term, phrase, match, match_phrase, prefix, regexp, wildcard, fuzzy
- Ranges: term range, numeric range, date range, boolean field
- Compound queries: combine conditions with
conjuncts(all must match),disjuncts(any can match), and boolean logic (must/should/must_not) - Query string syntax: a simple text-based way to write queries
- Geo spatial search: find things near a location or within a shape
- Vector search: approximate k-nearest neighbors (find similar items by vector)
- Synonym search: match words with the same meaning
- Hierarchical nested search: search structured, nested data
Scoring and ranking
bleve ranks results using two well-known scoring models: tf-idf and BM25. It also supports hybrid search — combining exact keyword matches with semantic (meaning-based) matches using two fusion methods: RRF (Reciprocal Rank Fusion) and RSF (Relative Score Fusion).
Other features
- Result pagination: page through large result sets
- Query time boosting: give extra weight to certain terms or fields during a search
- Match highlighting: show which parts of a document matched, with fragments of text
- Aggregations/faceting: group results by terms, numeric ranges, or date ranges (useful for filters and summaries)
How it works (code examples)
Indexing — store a document:
message := struct {
Id string
From string
Body string
}{
Id: "example",
From: "xyz@couchbase.com",
Body: "bleve indexing is easy",
}
mapping := bleve.NewIndexMapping()
index, err := bleve.New("example.bleve", mapping)
if err != nil {
panic(err)
}
index.Index(message.Id, message)
Querying — search the index:
index, _ := bleve.Open("example.bleve")
query := bleve.NewQueryStringQuery("bleve")
searchRequest := bleve.NewSearchRequest(query)
searchResult, _ := index.Search(searchRequest)
Command-line tool
bleve also ships a CLI (command-line interface) you can install with go install github.com/blevesearch/bleve/v2/cmd/bleve@latest. It lets you interact with a bleve index from the terminal. Commands include:
create— make a new indexindex— add files to the indexquery— search the indexcount— count documentsdump— show index contentscheck— verify index integrityfields— list fieldsmapping— show the mapping useddictionary— print the term dictionary for a fieldbulk— load many JSON documents at onceregistry— list compiled componentsscorch— interact with a scorch index (the underlying storage engine)
Text analysis
bleve includes general-purpose analyzers (customizable) plus pre-built text analyzers for many languages: Arabic, Bulgarian, Catalan, Chinese-Japanese-Korean, Kurdish, Danish, German, Greek, English, Spanish (Castilian and Galician), Basque, Persian, Finnish, French, Gaelic, Hindi, Croatian, Hungarian, Armenian, Indonesian, Italian, Dutch, Norwegian, Polish, Portuguese, Romanian, Russian, Swedish, and Turkish.
There's also a Text Analysis Wizard at bleveanalysis.couchbase.com to help you experiment with analyzers.
Getting help and license
- Issues/discussion: GitHub issues and a Google group
- License: Apache License Version 2.0
In short: bleve is a flexible, feature-rich search library for Go developers, with a CLI for quick tasks and broad language support for text analysis.
Related
- Project
- Project
- Project
- Project