This repository has been archived by the owner on Nov 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Merge pull request #16 from pelias/add-zsh-example
added example importer written in jq and zsh
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Pelias Document Service - Z shell Example | ||
|
||
This Z shell example app imports the list of [Boston, Massachusetts public schools](https://bostonopendata-boston.opendata.arcgis.com/datasets/1d9509a8b2fd485d9ad471ba2fdb1f90_0.geojson) into a [local](http://localhost:9200/pelias) Elasticsearch `pelias` index as venues. It requires [jq](https://stedolan.github.io/jq/) and [curl](https://curl.haxx.se/) to be installed. | ||
|
||
## Usage | ||
|
||
To run the example importer, enter the following at the command line: | ||
|
||
``` | ||
zsh boston_schools.zsh | ||
``` | ||
|
||
To verify, open [sense](http://localhost:5601/app/sense) and enter `GET pelias/venue/_search?pretty=true&q=*:*` to show indexed documents. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/zsh | ||
|
||
schoolsDataUrl='https://bostonopendata-boston.opendata.arcgis.com/datasets/1d9509a8b2fd485d9ad471ba2fdb1f90_0.geojson' | ||
count=0 | ||
|
||
# convert each school record into a URL | ||
for request in `curl $schoolsDataUrl | jq '.features[] | @uri "http://localhost:5000/synthesize/boston_schools/venue?id=\(.properties.SCH_ID)&lon=\(.geometry.coordinates[0])&lat=\(.geometry.coordinates[1])&name=\(.properties.SCH_LABEL)&house_number=\(.properties.ADDRESS | capture("^(?<num>\\\d+)\\\s").num )&street=\(.properties.ADDRESS | capture("^\\\d+\\\s+(?<street>.+)$").street )&postcode=\(.properties.ZIPCODE)" ' | sed s/\"//g `; do | ||
# extract the id for later use in POSTing to Elasticsearch | ||
[[ $request =~ 'id=([0-9]+)' ]] && id=$match[1] | ||
|
||
# call the document service, then POST the response to Elasticsearch | ||
curl $request | curl -X POST --data-binary @- http://localhost:9200/pelias/venue/$id | ||
|
||
((count++)) | ||
|
||
done | ||
|
||
echo "processed" $count "schools" |