Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkralidis committed Nov 13, 2024
1 parent 2714313 commit c9ef7bc
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 25 deletions.
2 changes: 1 addition & 1 deletion pygeoapi/api/itemtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ def post_collection_items(
HTTPStatus.BAD_REQUEST, headers, request.format,
'InvalidParameterValue', msg)
else:
LOGGER.debug('processing Elasticsearch CQL_JSON data')
LOGGER.debug('processing CQL_JSON data')
try:
filter_ = CQLModel.parse_raw(data)
except Exception:
Expand Down
3 changes: 3 additions & 0 deletions pygeoapi/provider/opensearch_.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,3 +737,6 @@ def update_query(input_query: Dict, cql: CQLModel):
query = OpenSearchQueryBuilder()
output_query = _build_query(query, cql)
s = s.query(output_query)

LOGGER.debug(f'Enhanced query: {json.dumps(s.to_dict())}')
return s.to_dict()
2 changes: 1 addition & 1 deletion tests/load_es_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,5 @@ def gendata(data):
with open(sys.argv[1], encoding='utf-8') as fh:
d = json.load(fh)

# call generator function to yield features into ES build API
# call generator function to yield features into ES bulk API
helpers.bulk(es, gendata(d))
59 changes: 36 additions & 23 deletions tests/load_opensearch_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
from pathlib import Path
import sys

from opensearchpy import OpenSearch
from opensearchpy import OpenSearch, helpers

os_ = OpenSearch(['localhost:9209'])

if len(sys.argv) < 3:
Expand All @@ -45,27 +46,26 @@
os_.indices.delete(index=index_name)

# index settings
settings = {
body = {
'settings': {
'index': {
'number_of_shards': 1,
'number_of_replicas': 0
}
}
}

mappings = {
'properties': {
'geometry': {
'type': 'geo_shape'
},
},
'mappings': {
'properties': {
'geometry': {
'type': 'geo_shape'
},
'properties': {
'nameascii': {
'type': 'text',
'fields': {
'raw': {
'type': 'keyword'
'properties': {
'nameascii': {
'type': 'text',
'fields': {
'raw': {
'type': 'keyword'
}
}
}
}
Expand All @@ -75,16 +75,29 @@
}


def gendata(data):
"""
Generator function to yield features
"""

for f in data['features']:
try:
f['properties'][id_field] = int(f['properties'][id_field])
except ValueError:
f['properties'][id_field] = f['properties'][id_field]
yield {
"_index": index_name,
"_id": f['properties'][id_field],
"_source": f
}


# create index
os_.indices.create(index=index_name, body=settings)
os_.indices.create(
index=index_name, body=body)

with open(sys.argv[1], encoding='utf-8') as fh:
d = json.load(fh)

for f in d['features']:
try:
id_field2 = int(f['properties'][id_field])
except ValueError:
id_field2 = f['properties'][id_field]

os_.index(index=index_name, body=f, id=id_field2, refresh=True)
# call generator function to yield features into OpenSearch bulk API
helpers.bulk(os_, gendata(d))

0 comments on commit c9ef7bc

Please sign in to comment.