Skip to content

Updating mapping to double for long #326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

- Update dynamic mapping for items to map long values to double versus float [#326](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/326)

## [v3.2.2] - 2024-12-15

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
},
# Default all other strings not otherwise specified to keyword
{"strings": {"match_mapping_type": "string", "mapping": {"type": "keyword"}}},
{"numerics": {"match_mapping_type": "long", "mapping": {"type": "float"}}},
{"numerics": {"match_mapping_type": "long", "mapping": {"type": "double"}}},
]

ES_ITEMS_MAPPINGS = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
from opensearchpy.helpers.search import Search
from starlette.requests import Request

from stac_fastapi.core import serializers
from stac_fastapi.core.extensions import filter
from stac_fastapi.core.serializers import CollectionSerializer, ItemSerializer
from stac_fastapi.core.utilities import MAX_LIMIT, bbox2polygon
from stac_fastapi.opensearch.config import (
AsyncOpensearchSettings as AsyncSearchSettings,
Expand Down Expand Up @@ -105,7 +105,7 @@
},
# Default all other strings not otherwise specified to keyword
{"strings": {"match_mapping_type": "string", "mapping": {"type": "keyword"}}},
{"numerics": {"match_mapping_type": "long", "mapping": {"type": "float"}}},
{"numerics": {"match_mapping_type": "long", "mapping": {"type": "double"}}},
]

ES_ITEMS_MAPPINGS = {
Expand Down Expand Up @@ -330,11 +330,9 @@ class DatabaseLogic:
client = AsyncSearchSettings().create_client
sync_client = SyncSearchSettings().create_client

item_serializer: Type[serializers.ItemSerializer] = attr.ib(
default=serializers.ItemSerializer
)
collection_serializer: Type[serializers.CollectionSerializer] = attr.ib(
default=serializers.CollectionSerializer
item_serializer: Type[ItemSerializer] = attr.ib(default=ItemSerializer)
collection_serializer: Type[CollectionSerializer] = attr.ib(
default=CollectionSerializer
)

extensions: List[str] = attr.ib(default=attr.Factory(list))
Expand Down
72 changes: 72 additions & 0 deletions stac_fastapi/tests/api/test_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import random
import uuid
from copy import deepcopy
from datetime import datetime, timedelta, timezone

import pytest
Expand Down Expand Up @@ -459,3 +461,73 @@ async def test_search_line_string_intersects(app_client, ctx):

resp_json = resp.json()
assert len(resp_json["features"]) == 1


@pytest.mark.asyncio
@pytest.mark.parametrize(
"value, expected",
[
(32767, 1), # Short Limit,
(2147483647, 1), # Int Limit
(2147483647 + 5000, 1), # Above int Limit
(21474836470, 1), # Above int Limit
# This value still fails to return 1
# Commenting out
# (9223372036854775807, 1),
],
)
async def test_big_int_eo_search(
app_client, txn_client, test_item, test_collection, value, expected
):

random_str = "".join(random.choice("abcdef") for i in range(random.randint(1, 5)))
collection_id = f"test-collection-eo-{random_str}"

test_big_int_item = test_item
del test_big_int_item["properties"]["eo:bands"]
test_big_int_item["collection"] = collection_id
test_big_int_collection = test_collection
test_big_int_collection["id"] = collection_id

# type number
attr = "eo:full_width_half_max"

stac_extensions = [
"https://stac-extensions.github.io/eo/v2.0.0/schema.json",
]

test_collection["stac_extensions"] = stac_extensions

test_item["stac_extensions"] = stac_extensions

await create_collection(txn_client, test_collection)

for val in [
value,
value + random.randint(10, 1010),
value - random.randint(10, 1010),
]:
item = deepcopy(test_item)
item["id"] = str(uuid.uuid4())
item["properties"][attr] = val
await create_item(txn_client, item)

params = {
"collections": [item["collection"]],
"filter": {
"args": [
{
"args": [
{"property": f"properties.{attr}"},
value,
],
"op": "=",
}
],
"op": "and",
},
}
resp = await app_client.post("/search", json=params)
resp_json = resp.json()
results = set([x["properties"][attr] for x in resp_json["features"]])
assert len(results) == expected
Loading