Bleve Command Line Examples

502 Views Asked by At

Are there any examples detailing the use of the Bleve CLI?

The functions and arguments are documented on the website, but in practice, it's hard to know what the method signatures and required fields are.

After some Googling, I found the following Github gist: https://gist.github.com/mschoch/5afa9ce2ae087dd240bf

But it appears to be a little out of date. Even after copying what I could from it, I'm still running into a number of inexplicable error messages (i.e. Error: error creating index: cannot create new index, path already exists).

Any info would be helpful.

Thanks.

1

There are 1 best solutions below

1
On

works for me

$ go version
go version go1.11.6 linux/amd64
$ go get -u github.com/blevesearch/bleve/...
$ sh test-bleve-search.sh 
+ set -e
+ cat
+ rm -fr test.bleve
+ bleve create ./test.bleve --mapping ./mapping.json
+ cat
+ bleve index test.bleve test.json
Indexing: test
+ bleve query test.bleve location.state:IN
1 matches, showing 1 through 1, took 173.341µs
    1. test (0.306853)
    location.state
        IN

with a fixed script

#!/bin/sh

set -x
set -e

# create a custom mapping
cat > mapping.json << MAPPING
{
  "types": {
    "_default": {
      "properties": {
        "location": {
          "properties": {
            "state": {
              "fields": [
                {
                  "name": "state",
                  "type": "text",
                  "analyzer": "keyword",
                  "store": true,
                  "index": true,
                  "include_term_vectors": true,
                  "include_in_all": true
                }
              ]
            }
          }
        }
      }
    }
  }
}
MAPPING

rm -fr test.bleve

# create index
bleve create ./test.bleve --mapping ./mapping.json

# create JSON file to index
cat > test.json <<DELIM
{
    "name": "test",
    "location": {
        "address1": "777 TEST ROAD",
        "address2": "",
        "city": "HIGHLAND HEIGHTS",
        "state": "IN",
        "zip": "777777",
        "countryCode": "",
        "latitude": 41.549536,
        "longitude": -81.454717
    }
}
DELIM

# index test file
bleve index test.bleve test.json

# query for the file we indexed
bleve query test.bleve location.state:IN