Skip to content

Instantly share code, notes, and snippets.

@mschoch
mschoch / test-bleve-search.sh
Last active June 18, 2023 03:53
bleve - create index, index JSON, query index
#!/bin/sh
# create a custom mapping
cat > /tmp/mapping.json << MAPPING
{
"types": {
"_default": {
"properties": {
"location": {
"properties": {
@mschoch
mschoch / elasticsearch-docker-script
Last active November 19, 2022 19:38
A script to fix ownership of Elasticsearch data directory (when mounted as a volume in docker), then switch to elasticsearch user and launch elasticsearch
#!/bin/sh
# fix permissions (wrong if docker mounted volume)
chown -R elasticsearch:elasticsearch /var/lib/elasticsearch
# now switch to elasticsearch user and run in foreground
echo Starting: /usr/share/elasticsearch/bin/elasticsearch -Des.default.config=$CONF_FILE -Des.default.path.home=/usr/share/elasticsearch -Des.default.path.logs=$LOG_DIR -Des.default.path.data=/var/lib/elasticsearch -Des.default.path.work=/tmp/elasticsearch -Des.default.path.conf=$CONF_DIR $@
su elasticsearch -s /bin/sh -c "/usr/share/elasticsearch/bin/elasticsearch -Des.default.config=$CONF_FILE -Des.default.path.home=/usr/share/elasticsearch -Des.default.path.logs=$LOG_DIR -Des.default.path.data=/var/lib/elasticsearch -Des.default.path.work=/tmp/elasticsearch -Des.default.path.conf=$CONF_DIR $@"
@mschoch
mschoch / force_mege.go
Created March 3, 2021 21:45
A utility function to force merge a Bleve index into a single segment
func forceMerge(index bleve.Index) error {
internalIndex, err := index.Advanced()
if err != nil {
return fmt.Errorf("unable to access internal index: %v", err)
}
if scorchIndex, ok := internalIndex.(*scorch.Scorch); ok {
numFiles := scorchIndex.StatsMap()["num_files_on_disk"].(uint64)
for numFiles > 2 {
err = scorchIndex.ForceMerge(context.Background(), nil)
if err != nil {
package main
import (
"fmt"
"os"
"github.com/blevesearch/bleve"
"github.com/blevesearch/bleve/analysis/language/fr"
)
@mschoch
mschoch / scoring.md
Created July 4, 2016 20:17
Introduction to Bleve Scoring

Scoring

Scoring of complex queries involves a few different pieces. To understand how they fit together, it's helpful to first look a simple query, then add in complexities one at a time until we have the complete picture.

Term Query

The simplest query we can run is a term query for a single term. Consider a term search for light in the field description of the beer-search dataset. The top scoring hit is iron_city_brewing_co-ic_light and when we ask Bleve to explain the scoring we get:

"explanation": {

"value": 2.024174152548743,

#!/bin/sh
# create temp directory to do all work
tmpfile=$(mktemp -d)
echo "Working in $tmpfile"
cd $tmpfile
# check out gocbcore
git clone git@github.com:couchbase/gocbcore.git
[ 19%] Linking CXX executable couch_dbdump
/usr/bin/ld: ../tlm/deps/flatbuffers.exploded/lib/libflatbuffers.a(idl_parser.cpp.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../tlm/deps/flatbuffers.exploded/lib/libflatbuffers.a(idl_gen_text.cpp.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../tlm/deps/flatbuffers.exploded/lib/libflatbuffers.a(util.cpp.o): relocation R_X86_64_32S against symbol `_ZTVSt9basic_iosIcSt11char_traitsIcEE@@GLIBCXX_3.4' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
couchstore/CMakeFiles/couch_dbdump.dir/build.make:241: recipe for target 'couchstore/couch_dbdump' failed
make[4]: *** [couchstore/couch_dbdump] Error 1
CMakeFiles/Makefile2:9108: recipe for target 'couchstore/CMakeFiles/couch_dbdump.dir/all' fai
mschoch@mschoch-virtualbox:/mnt/build$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.4 LTS
Release: 18.04
Codename: bionic
mschoch@mschoch-virtualbox:/mnt/build$ uname -a
Linux mschoch-virtualbox 5.3.0-42-generic #34~18.04.1-Ubuntu SMP Fri Feb 28 13:42:26 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
@mschoch
mschoch / main.go
Created March 10, 2020 14:32
reproduce deleted files still open (as shown by lsof)
package main
import (
"github.com/blevesearch/bleve"
"github.com/blevesearch/bleve/index/scorch"
"log"
)
func main() {
Poky (Yocto Project Reference Distro) SDK installer version 2.1.3
=================================================================
Enter target directory for SDK (default: /opt/poky/2.1.3):
You are about to install the SDK to "/opt/poky/2.1.3". Proceed[Y/n]? Y
[sudo] password for mschoch:
Extracting SDK......................................................................................done
Setting it up...done
SDK has been successfully set up and is ready to be used.
Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g.
$ . /opt/poky/2.1.3/environment-setup-cortexa9hf-neon-poky-linux-gnueabi