bleve

command module
v0.0.0-...-cd46311 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2026 License: Apache-2.0 Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Simple Bleve test

A small command-line program for trying out the Bleve search engine.

On startup it builds an in-memory index, seeds it with 100 randomly generated users, and then reads search queries from standard input. Each query is run against the index and the results are printed as tables.

Every user has the following fields, all of which are indexed:

Field Type Example
id number 1042
firstname text Emily
lastname text Garcia
gender text female
birthdate date 1971-03-14
age number 55
created_at date 2019-11-02
last_online_at date 2020-04-19

The data is generated fresh on every run, so names and ages will differ between runs.

Requirements

Go 1.27.1 or newer. If you have an older Go installed, the go command will download the required toolchain automatically the first time you build.

Running it

git clone https://github.com/emmanuelay/bleve.git
cd bleve
go run .

You should see:

Simple Bleve test
Type searchstring and press ENTER (ex: '+ gender:female + age:>=45') or type 'exit' to quit
 >

Type a query and press Enter. Type exit to quit.

Example queries

Queries use Bleve's query string syntax. A few to try:

Query Meaning
garcia Match garcia in any field
lastname:garcia Match garcia in the last name field only
firstname:em* First names starting with em
+gender:female +age:>=45 Female users aged 45 or older (both terms required)
+age:>=18 +age:<25 Users aged 18 to 24
+gender:male -lastname:smith Male users whose last name is not Smith

A + prefix makes a term required and - excludes it. Terms without a prefix are optional, so age:>=18 age:<25 would match users who satisfy either condition rather than both. The prefix must be attached directly to the term, with no space in between.

What to expect

Each query prints two tables. The first lists the top five matching users:

 > +gender:female +age:>=45
+------+------------+-----------+-----+
|    # | FIRST NAME | LAST NAME | AGE |
+------+------------+-----------+-----+
| 1021 | Emily      | Anderson  |  55 |
| 1075 | Sofia      | Johnson   |  45 |
| 1060 | Mia        | Wilson    |  63 |
| 1093 | Zoey       | Miller    |  62 |
| 1016 | Chloe      | Wilson    |  50 |
+------+------------+-----------+-----+

Results are paginated with a page size of 5, so at most five hits are shown even if more users matched. The page size and offset are set in search() in main.go if you want to change them.

The second table summarises the two facets that are requested with every search, gender and age_group. The TOTAL column is the number of hits that had a value for that field, which is the full match count, not just the five rows shown:

+---+-----------+-------+---------+-------+
| # | FIELD     | TOTAL | MISSING | OTHER |
+---+-----------+-------+---------+-------+
| 0 | gender    |    25 |       0 |     0 |
| 0 | age_group |    25 |       0 |     0 |
+---+-----------+-------+---------+-------+

The age_group facet buckets users into teenager, young-adult, adult, senior-adult and senior ranges. The individual bucket counts are computed by Bleve but are not printed by this program; only the totals are.

A query that matches nothing prints the two table headers with no rows and facet totals of zero.

A query that cannot be parsed prints an error and returns to the prompt:

 > "unterminated
Error while searching!
 parse error: unterminated quote
 >

Other query types

search() in main.go contains commented-out examples of building numeric range queries, term queries, and conjunction queries programmatically rather than through the query string parser. Uncomment and adapt them to experiment.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址