Blast is a full text search and indexing server, written in Go, built on top of Bleve.
Blast is a full text search and indexing server, written in Go, built on top of Bleve.
This project has not been maintained for a long time.
Blast is a full-text search and indexing server written in Go built on top of Bleve.
It provides functions through gRPC (HTTP/2 + Protocol Buffers) or traditional RESTful API (HTTP/1.1 + JSON).
Blast implements a Raft consensus algorithm by hashicorp/raft. It achieves consensus across all the nodes, ensuring that every change made to the system is made to a quorum of nodes, or none at all.
Blast makes it easy for programmers to develop search applications with advanced features.
Blast requires some C/C++ libraries if you need to enable cld2, icu, libstemmer or leveldb. The following sections are instructions for satisfying dependencies on particular platforms.
…$ brew install \
icu4c \
leveldb
$ export GOPATH=${HOME}/go
$ go get -u -v github.com/blevesearch/cld2
$ cd ${GOPATH}/src/github.com/blevesearch/cld2
$ git clone https://github.com/CLD2Owners/cld2.git
$ cd cld2/internal
$ perl -p -i -e 's/soname=/install_name,/' compile_libs.sh
$ ./compile_libs.sh
$ sudo cp *.so /usr/local/libBuilding Blast as following:
$ mkdir -p ${GOPATH}/src/github.com/mosuka
$ cd ${GOPATH}/src/github.com/mosuka
$ git clone https://github.com/mosuka/blast.git
$ cd blast
$ makeIf you omit GOOS or GOARCH, it will build the binary of the platform you are using.
If you want to specify the target platform, please set GOOS and GOARCH environment variables.
$ make GOOS=linux build$ make GOOS=darwin build$ make GOOS=windows buildBlast supports some Bleve Extensions (blevex). If you want to build with them, please set CGO_LDFLAGS, CGO_CFLAGS, CGO_ENABLED and BUILD_TAGS. For example, build LevelDB to be available for index storage as follows:
$ make GOOS=linux \
BUILD_TAGS=icu \
CGO_ENABLED=1 \
build$ make GOOS=linux \
BUILD_TAGS="kagome icu libstemmer cld2" \
CGO_ENABLED=1 \
build$ make GOOS=darwin \
BUILD_TAGS="kagome icu libstemmer cld2" \
CGO_ENABLED=1 \
CGO_LDFLAGS="-L/usr/local/opt/icu4c/lib" \
CGO_CFLAGS="-I/usr/local/opt/icu4c/include" \
buildRefer to the following table for the build flags of the supported Bleve extensions:
| BUILD_TAGS | CGO_ENABLED | Description |
|---|---|---|
| cld2 | 1 | Enable Compact Language Detector |
| kagome | 0 | Enable Japanese Language Analyser |
| icu | 1 | Enable ICU Tokenizer, Thai Language Analyser |
| libstemmer | 1 | Enable Language Stemmer (Danish, German, English, Spanish, Finnish, French, Hungarian, Italian, Dutch, Norwegian, Portuguese, Romanian, Russian, Swedish, Turkish) |
If you want to enable the feature whose CGO_ENABLE is 1, please install it referring to the Install build dependencies section above.
You can see the binary file when build successful like so:
$ ls ./bin
blastIf you want to test your changes, run command like following:
$ make testIf you want to specify the target platform, set GOOS and GOARCH environment variables in the same way as the build.
To create a distribution package, run the following command:
$ make distBlast can change its startup options with configuration files, environment variables, and command line arguments.
Refer to the following table for the options that can be configured.
| CLI Flag | Environment variable | Configuration File | Description |
|---|---|---|---|
| --config-file | - | - | config file. if omitted, blast.yaml in /etc and home directory will be searched |
| --id | BLAST_ID | id | node ID |
| --raft-address | BLAST_RAFT_ADDRESS | raft_address | Raft server listen address |
| --grpc-address | BLAST_GRPC_ADDRESS | grpc_address | gRPC server listen address |
| --http-address | BLAST_HTTP_ADDRESS | http_address | HTTP server listen address |
| --data-directory | BLAST_DATA_DIRECTORY | data_directory | data directory which store the index and Raft logs |
| --mapping-file | BLAST_MAPPING_FILE | mapping_file | path to the index mapping file |
| --peer-grpc-address | BLAST_PEER_GRPC_ADDRESS | peer_grpc_address | listen address of the existing gRPC server in the joining cluster |
| --certificate-file | BLAST_CERTIFICATE_FILE | certificate_file | path to the client server TLS certificate file |
| --key-file | BLAST_KEY_FILE | key_file | path to the client server TLS key file |
| --common-name | BLAST_COMMON_NAME | common_name | certificate common name |
| --cors-allowed-methods | BLAST_CORS_ALLOWED_METHODS | cors_allowed_methods | CORS allowed methods (ex: GET,PUT,DELETE,POST) |
| --cors-allowed-origins | BLAST_CORS_ALLOWED_ORIGINS | cors_allowed_origins | CORS allowed origins (ex: http://localhost:8080,http://localhost:80) |
| --cors-allowed-headers | BLAST_CORS_ALLOWED_HEADERS | cors_allowed_headers | CORS allowed headers (ex: content-type,x-some-key) |
| --log-level | BLAST_LOG_LEVEL | log_level | log level |
| --log-file | BLAST_LOG_FILE | log_file | log file |
| --log-max-size | BLAST_LOG_MAX_SIZE | log_max_size | max size of a log file in megabytes |
| --log-max-backups | BLAST_LOG_MAX_BACKUPS | log_max_backups | max backup count of log files |
| --log-max-age | BLAST_LOG_MAX_AGE | log_max_age | max age of a log file in days |
| --log-compress | BLAST_LOG_COMPRESS | log_compress | compress a log file |
Starting server is easy as follows:
$ ./bin/blast start \
--id=node1 \
--raft-address=:7000 \
--http-address=:8000 \
--grpc-address=:9000 \
--data-directory=/tmp/blast/node1 \
--mapping-file=./examples/example_mapping.jsonYou can get the node information with the following command:
$ ./bin/blast node | jq .or the following URL:
$ curl -X GET http://localhost:8000/v1/node | jq .The result of the above command is:
{
"node": {
"raft_address": ":7000",
"metadata": {
"grpc_address": ":9000",
"http_address": ":8000"
},
"state": "Leader"
}
}You can check the health status of the node.
$ ./bin/blast healthcheck | jq .Also provides the following REST APIs
This endpoint always returns 200 and should be used to check server health.
$ curl -X GET http://localhost:8000/v1/liveness_check | jq .This endpoint returns 200 when server is ready to serve traffic (i.e. respond to queries).
$ curl -X GET http://localhost:8000/v1/readiness_check | jq .To put a document, execute the following command:
…or, you can use the RESTful API as follows:
…or
$ curl -X PUT 'http://127.0.0.1:8000/v1/documents/1' -H "Content-Type: application/json" --data-binary @./examples/example_doc_1.jsonTo get a document, execute the following command:
$ ./bin/blast get 1 | jq .or, you can use the RESTful API as follows:
$ curl -X GET 'http://127.0.0.1:8000/v1/documents/1' | jq .You can see the result. The result of the above command is:
…To search documents, execute the following command:
$ ./bin/blast search '
{
"search_request": {
"query": {
"query": "+_all:search"
},
"size": 10,
"from": 0,
"fields": [
"*"
],
"sort": [
"-_score"
]
}
}
' | jq .or, you can use the RESTful API as follows:
$ curl -X POST 'http://127.0.0.1:8000/v1/search' --data-binary '
{
"search_request": {
"query": {
"query": "+_all:search"
},
"size": 10,
"from": 0,
"fields": [
"*"
],
"sort": [
"-_score"
]
}
}
' | jq .You can see the result. The result of the above command is:
…Deleting a document, execute the following command:
$ ./bin/blast delete 1or, you can use the RESTful API as follows:
$ curl -X DELETE 'http://127.0.0.1:8000/v1/documents/1'To index documents in bulk, execute the following command:
$ ./bin/blast bulk-index --file ./examples/example_bulk_index.jsonor, you can use the RESTful API as follows:
$ curl -X PUT 'http://127.0.0.1:8000/v1/documents' -H "Content-Type: application/x-ndjson" --data-binary @./examples/example_bulk_index.jsonTo delete documents in bulk, execute the following command:
$ ./bin/blast bulk-delete --file ./examples/example_bulk_delete.txtor, you can use the RESTful API as follows:
$ curl -X DELETE 'http://127.0.0.1:8000/v1/documents' -H "Content-Type: text/plain" --data-binary @./examples/example_bulk_delete.txtBlast is easy to bring up the cluster. the node is already running, but that is not fault tolerant. If you need to increase the fault tolerance, bring up 2 more data nodes like so:
$ ./bin/blast start \
--id=node2 \
--raft-address=:7001 \
--http-address=:8001 \
--grpc-address=:9001 \
--peer-grpc-address=:9000 \
--data-directory=/tmp/blast/node2 \
--mapping-file=./examples/example_mapping.json$ ./bin/blast start \
--id=node3 \
--raft-address=:7002 \
--http-address=:8002 \
--grpc-address=:9002 \
--peer-grpc-address=:9000 \
--data-directory=/tmp/blast/node3 \
--mapping-file=./examples/example_mapping.jsonAbove example shows each Blast node running on the same host, so each node must listen on different ports. This would not be necessary if each node ran on a different host.
This instructs each new node to join an existing node, each node recognizes the joining clusters when started. So you have a 3-node cluster. That way you can tolerate the failure of 1 node. You can check the cluster with the following command:
$ ./bin/blast cluster | jq .or, you can use the RESTful API as follows:
$ curl -X GET 'http://127.0.0.1:8000/v1/cluster' | jq .You can see the result in JSON format. The result of the above command is:
…Recommend 3 or more odd number of nodes in the cluster. In failure scenarios, data loss is inevitable, so avoid deploying single nodes.
The above example, the node joins to the cluster at startup, but you can also join the node that already started on standalone mode to the cluster later, as follows:
$ ./bin/blast join --grpc-address=:9000 node2 127.0.0.1:9001or, you can use the RESTful API as follows:
$ curl -X PUT 'http://127.0.0.1:8000/v1/cluster/node2' --data-binary '
{
"raft_address": ":7001",
"metadata": {
"grpc_No open issues yet, or sync has not completed.