From 4b85a6a8eb8c19b979bf29b5dbefb50f18f12380 Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Mon, 11 Oct 2021 20:21:44 -0400 Subject: [PATCH] detect exact match for ES property queries (#793) * detect exact match for ES property queries * detect exact match for ES property queries * update tests --- pygeoapi/provider/elasticsearch_.py | 8 +++++++- tests/test_elasticsearch__provider.py | 6 +++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pygeoapi/provider/elasticsearch_.py b/pygeoapi/provider/elasticsearch_.py index 3d45a8b..eeebdea 100644 --- a/pygeoapi/provider/elasticsearch_.py +++ b/pygeoapi/provider/elasticsearch_.py @@ -236,13 +236,19 @@ class ElasticsearchProvider(BaseProvider): if properties: LOGGER.debug('processing properties') for prop in properties: + prop_name = self.mask_prop(prop[0]) pf = { 'match': { - self.mask_prop(prop[0]): prop[1] + prop_name: { + 'query': prop[1] + } } } query['query']['bool']['filter'].append(pf) + if '|' not in prop[1]: + pf['match'][prop_name]['minimum_should_match'] = '100%' + if sortby: LOGGER.debug('processing sortby') query['sort'] = [] diff --git a/tests/test_elasticsearch__provider.py b/tests/test_elasticsearch__provider.py index 6dea719..d720543 100644 --- a/tests/test_elasticsearch__provider.py +++ b/tests/test_elasticsearch__provider.py @@ -161,9 +161,9 @@ def test_query(config): assert results['features'][0]['properties']['nameascii'] == 'Vatican City' results = p.query(properties=[('nameascii', 'Vatican City')]) - assert len(results['features']) == 4 - assert results['numberMatched'] == 4 - assert results['numberReturned'] == 4 + assert len(results['features']) == 1 + assert results['numberMatched'] == 1 + assert results['numberReturned'] == 1 results = p.query(limit=1) assert len(results['features']) == 1