Last active
June 18, 2023 03:53
-
-
Save mschoch/5afa9ce2ae087dd240bf to your computer and use it in GitHub Desktop.
bleve - create index, index JSON, query index
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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