Skip to content
This repository has been archived by the owner on Nov 22, 2019. It is now read-only.

Commit

Permalink
feat: Merge pull request #16 from pelias/add-zsh-example
Browse files Browse the repository at this point in the history
added example importer written in jq and zsh
  • Loading branch information
trescube authored Oct 3, 2017
2 parents 90bc65c + af81e77 commit af4810e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
13 changes: 13 additions & 0 deletions examples/zsh/README.md
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.
18 changes: 18 additions & 0 deletions examples/zsh/boston_schools.zsh
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"

0 comments on commit af4810e

Please sign in to comment.