From d9081fe9e180ef8f3c306b6207a9bd0228a80dc8 Mon Sep 17 00:00:00 2001 From: Willi Date: Wed, 16 Oct 2024 10:05:12 +0200 Subject: [PATCH] Fix date type inferring to handle - and : in format pattern --- arlas/cli/index.py | 9 +++++++-- arlas/cli/model_infering.py | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/arlas/cli/index.py b/arlas/cli/index.py index e0dc652..6b49bb0 100644 --- a/arlas/cli/index.py +++ b/arlas/cli/index.py @@ -105,8 +105,13 @@ def mapping( if len(tmp) == 2: types[tmp[0]] = tmp[1] else: - print("Error: invalid field_mapping \"{}\". The format is \"field:type\" like \"fragment.location:geo_point\"".format(fm), file=sys.stderr) - exit(1) + if tmp[1].startswith("date-"): + # Dates can have format patterns containing ':' + tmp = fm.split(":", 1) + types[tmp[0]] = tmp[1] + else: + print(f"Error: invalid field_mapping \"{fm}\". The format is \"field:type\" like \"fragment.location:geo_point\"", file=sys.stderr) + exit(1) mapping = make_mapping(file=file, nb_lines=nb_lines, types=types, no_fulltext=no_fulltext) if push_on and config: Service.create_index( diff --git a/arlas/cli/model_infering.py b/arlas/cli/model_infering.py index a334da8..6658f1e 100644 --- a/arlas/cli/model_infering.py +++ b/arlas/cli/model_infering.py @@ -151,7 +151,8 @@ def __generate_mapping__(tree, mapping, no_fulltext: list[str]): __generate_mapping__(v, mapping[k]["properties"], no_fulltext) else: if t.startswith("date-"): - mapping[k] = {"type": "date", "format": t.split("-")[1]} + # Dates can have format patterns containing '-' + mapping[k] = {"type": "date", "format": t.split("-", 1)[1]} else: mapping[k] = {"type": t} if t in ["keyword", "text"]: