Skip to content

Instantly share code, notes, and snippets.

@mschoch
Last active June 18, 2023 03:53
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mschoch/5afa9ce2ae087dd240bf to your computer and use it in GitHub Desktop.
Save mschoch/5afa9ce2ae087dd240bf to your computer and use it in GitHub Desktop.
bleve - create index, index JSON, query index
#!/bin/sh
# create a custom mapping
cat > /tmp/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
# create index
bleve_create -mapping /tmp/mapping.json -index /tmp/test.bleve
# create JSON file to index
cat > /tmp/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 -index /tmp/test.bleve /tmp/test.json
# query for the file we indexed
bleve_query -index /tmp/test.bleve location.state:IN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment