Skip to content

Commit 64d646f

Browse files
Updating mapping to double for long (#326)
**Related Issue(s):** - #320 **Description:** Convert dynamic mapping from ``` {"numerics": {"match_mapping_type": "long", "mapping": {"type": "float"}}}, ``` ``` {"numerics": {"match_mapping_type": "long", "mapping": {"type": "double"}}}, ``` **PR Checklist:** - [x] Code is formatted and linted (run `pre-commit run --all-files`) - [x] Tests pass (run `make test`) - [x] Documentation has been updated to reflect changes, if applicable - [x] Changes are added to the changelog --------- Co-authored-by: Jonathan Healy <[email protected]>
1 parent 22c10f7 commit 64d646f

File tree

4 files changed

+83
-7
lines changed

4 files changed

+83
-7
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1111

1212
### Changed
1313

14+
- Updated dynamic mapping for items to map long values to double versus float [#326](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/326)
1415
- Extended Datetime Search to search on start_datetime and end_datetime as well as datetime fields. [#182](https://github.com/stac-utils/stac-fastapi-elasticsearch/pull/182)
1516

1617
### Fixed

stac_fastapi/core/stac_fastapi/core/database_logic.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@ class Geometry(Protocol): # noqa
9696
},
9797
# Default all other strings not otherwise specified to keyword
9898
{"strings": {"match_mapping_type": "string", "mapping": {"type": "keyword"}}},
99-
{"numerics": {"match_mapping_type": "long", "mapping": {"type": "float"}}},
99+
{"long_to_double": {"match_mapping_type": "long", "mapping": {"type": "double"}}},
100+
{
101+
"double_to_double": {
102+
"match_mapping_type": "double",
103+
"mapping": {"type": "double"},
104+
}
105+
},
100106
]
101107

102108
ES_ITEMS_MAPPINGS = {

stac_fastapi/opensearch/stac_fastapi/opensearch/database_logic.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from opensearchpy.helpers.search import Search
1414
from starlette.requests import Request
1515

16-
from stac_fastapi.core import serializers
1716
from stac_fastapi.core.base_database_logic import BaseDatabaseLogic
1817
from stac_fastapi.core.database_logic import (
1918
COLLECTIONS_INDEX,
@@ -31,6 +30,7 @@
3130
mk_item_id,
3231
)
3332
from stac_fastapi.core.extensions import filter
33+
from stac_fastapi.core.serializers import CollectionSerializer, ItemSerializer
3434
from stac_fastapi.core.utilities import MAX_LIMIT, bbox2polygon
3535
from stac_fastapi.opensearch.config import (
3636
AsyncOpensearchSettings as AsyncSearchSettings,
@@ -146,11 +146,9 @@ class DatabaseLogic(BaseDatabaseLogic):
146146
client = AsyncSearchSettings().create_client
147147
sync_client = SyncSearchSettings().create_client
148148

149-
item_serializer: Type[serializers.ItemSerializer] = attr.ib(
150-
default=serializers.ItemSerializer
151-
)
152-
collection_serializer: Type[serializers.CollectionSerializer] = attr.ib(
153-
default=serializers.CollectionSerializer
149+
item_serializer: Type[ItemSerializer] = attr.ib(default=ItemSerializer)
150+
collection_serializer: Type[CollectionSerializer] = attr.ib(
151+
default=CollectionSerializer
154152
)
155153

156154
extensions: List[str] = attr.ib(default=attr.Factory(list))

stac_fastapi/tests/api/test_api.py

+71
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import random
12
import uuid
23
from copy import deepcopy
34
from datetime import datetime, timedelta
@@ -628,3 +629,73 @@ async def test_search_line_string_intersects(app_client, ctx):
628629

629630
resp_json = resp.json()
630631
assert len(resp_json["features"]) == 1
632+
633+
634+
@pytest.mark.asyncio
635+
@pytest.mark.parametrize(
636+
"value, expected",
637+
[
638+
(32767, 1), # Short Limit,
639+
(2147483647, 1), # Int Limit
640+
(2147483647 + 5000, 1), # Above int Limit
641+
(21474836470, 1), # Above int Limit
642+
# This value still fails to return 1
643+
# Commenting out
644+
# (9223372036854775807, 1),
645+
],
646+
)
647+
async def test_big_int_eo_search(
648+
app_client, txn_client, test_item, test_collection, value, expected
649+
):
650+
651+
random_str = "".join(random.choice("abcdef") for i in range(random.randint(1, 5)))
652+
collection_id = f"test-collection-eo-{random_str}"
653+
654+
test_big_int_item = test_item
655+
del test_big_int_item["properties"]["eo:bands"]
656+
test_big_int_item["collection"] = collection_id
657+
test_big_int_collection = test_collection
658+
test_big_int_collection["id"] = collection_id
659+
660+
# type number
661+
attr = "eo:full_width_half_max"
662+
663+
stac_extensions = [
664+
"https://stac-extensions.github.io/eo/v2.0.0/schema.json",
665+
]
666+
667+
test_collection["stac_extensions"] = stac_extensions
668+
669+
test_item["stac_extensions"] = stac_extensions
670+
671+
await create_collection(txn_client, test_collection)
672+
673+
for val in [
674+
value,
675+
value + random.randint(10, 1010),
676+
value - random.randint(10, 1010),
677+
]:
678+
item = deepcopy(test_item)
679+
item["id"] = str(uuid.uuid4())
680+
item["properties"][attr] = val
681+
await create_item(txn_client, item)
682+
683+
params = {
684+
"collections": [item["collection"]],
685+
"filter": {
686+
"args": [
687+
{
688+
"args": [
689+
{"property": f"properties.{attr}"},
690+
value,
691+
],
692+
"op": "=",
693+
}
694+
],
695+
"op": "and",
696+
},
697+
}
698+
resp = await app_client.post("/search", json=params)
699+
resp_json = resp.json()
700+
results = set([x["properties"][attr] for x in resp_json["features"]])
701+
assert len(results) == expected

0 commit comments

Comments
 (0)