abstract ES test loader to accept id field as argument (#324)

This commit is contained in:
Tom Kralidis
2019-12-23 12:33:31 -05:00
committed by GitHub
parent 1ce7ac8cfb
commit ac73e95398
3 changed files with 11 additions and 7 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ install:
before_script:
- sleep 20
- python3 tests/load_es_data.py tests/data/ne_110m_populated_places_simple.geojson
- python3 tests/load_es_data.py tests/data/ne_110m_populated_places_simple.geojson geonameid
- pygeoapi generate-openapi-document -c pygeoapi-config.yml > pygeoapi-openapi.yml
- psql -U postgres -c 'create database test'
- psql -U postgres -d test -c 'create extension postgis'
+1 -1
View File
@@ -44,7 +44,7 @@ until $(curl -sSf -XGET --insecure 'http://localhost:9200/_cluster/health?wait_f
done
echo "Elasticsearch seems to be working - Adding ne_110m_populated_places_simple.geojson to ES"
python /load_es_data.py /usr/share/elasticsearch/data/ne_110m_populated_places_simple.geojson
python /load_es_data.py /usr/share/elasticsearch/data/ne_110m_populated_places_simple.geojson geonameid
echo "Seems that data was loaded"
+9 -5
View File
@@ -36,11 +36,12 @@ es = Elasticsearch()
type_name = 'FeatureCollection'
if len(sys.argv) == 1:
print('Usage: {} <path/to/data.geojson>'.format(sys.argv[0]))
if len(sys.argv) == 2:
print('Usage: {} <path/to/data.geojson> <id-field>'.format(sys.argv[0]))
sys.exit(1)
index_name = os.path.splitext(os.path.basename(sys.argv[1]))[0]
index_name = os.path.splitext(os.path.basename(sys.argv[1]))[0].lower()
id_field = sys.argv[2]
if es.indices.exists(index_name):
es.indices.delete(index_name)
@@ -77,6 +78,9 @@ with open(sys.argv[1]) as fh:
d = json.load(fh)
for f in d['features']:
f['properties']['geonameid'] = int(f['properties']['geonameid'])
try:
f['properties'][id_field] = int(f['properties'][id_field])
except ValueError:
f['properties'][id_field] = f['properties'][id_field]
res = es.index(index=index_name, doc_type=type_name,
id=f['properties']['geonameid'], body=f)
id=f['properties'][id_field], body=f)