From ce464e668e7a621cd04ebec80228476f3a685036 Mon Sep 17 00:00:00 2001 From: crimson-gao <1291463831@qq.com> Date: Tue, 15 Sep 2026 16:28:08 +0800 Subject: [PATCH 1/4] feat: support automatically discovered text index fields --- HISTORY.md | 6 +++ aliyun/log/index_config.py | 18 +++++-- aliyun/log/index_config.pyi | 4 +- aliyun/log/version.py | 2 +- tests/ci/build-test/test_index_config.py | 67 ++++++++++++++++++++++++ 5 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 tests/ci/build-test/test_index_config.py diff --git a/HISTORY.md b/HISTORY.md index 66b5992..b98a454 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,11 @@ # Release History +## 0.9.52 (2026-09-15) + +**Feature** + +- support auto_text_keys in index creation, updates and responses, with auto_key_detect defaulting to False and auto_text_keys to an empty list. Updates replace the full auto_text_keys list; preserve existing fields when changing other index settings. + ## 0.9.51 (2026-09-07) **Breaking Changes** diff --git a/aliyun/log/index_config.py b/aliyun/log/index_config.py index 7310259..32bd35f 100755 --- a/aliyun/log/index_config.py +++ b/aliyun/log/index_config.py @@ -190,15 +190,22 @@ class IndexLineConfig(object): :param chinese: enable Chinese words segmentation :type auto_key_detect: bool - :param auto_key_detect: enable auto key detection + :param auto_key_detect: enable auto key detection, defaults to False :type auto_key_count_limit: int :param auto_key_count_limit: limit for auto key count, only effective when auto_key_detect is True + :type auto_text_keys: string list + :param auto_text_keys: automatically discovered text fields, defaults to an empty list. + Fields reuse the line token and case-sensitivity settings. Updates replace the + complete list; preserve existing fields when changing other index settings. + To use a numeric type or custom settings, move the field to explicit keys + and remove it from this list. + """ def __init__(self, token_list=None, case_sensitive=False, include_keys=None, exclude_keys=None, chinese=None, - auto_key_detect=None, auto_key_count_limit=None): + auto_key_detect=False, auto_key_count_limit=None, auto_text_keys=None): if token_list is None: token_list = [] self.token_list = token_list @@ -206,9 +213,11 @@ def __init__(self, token_list=None, case_sensitive=False, include_keys=None, exc self.chn = bool(chinese) self.auto_key_detect = auto_key_detect self.auto_key_count_limit = auto_key_count_limit + self.auto_text_keys = list(auto_text_keys) if auto_text_keys is not None else [] def to_json(self): - json_value = {"token": self.token_list, "caseSensitive": bool(self.case_sensitive)} + json_value = {"token": self.token_list, "caseSensitive": bool(self.case_sensitive), + "auto_text_keys": self.auto_text_keys} if self.chn is not None: json_value["chn"] = bool(self.chn) @@ -223,7 +232,8 @@ def from_json(self, json_value): self.token_list = json_value["token"] self.case_sensitive = bool(json_value.get("caseSensitive", False)) self.chn = bool(json_value["chn"]) if "chn" in json_value else None - self.auto_key_detect = bool(json_value["auto_key_detect"]) if "auto_key_detect" in json_value else None + self.auto_key_detect = bool(json_value.get("auto_key_detect", False)) + self.auto_text_keys = list(json_value.get("auto_text_keys") or []) self.auto_key_count_limit = int(json_value["auto_key_count_limit"]) if "auto_key_count_limit" in json_value else None diff --git a/aliyun/log/index_config.pyi b/aliyun/log/index_config.pyi index 01a57eb..f5dd0b1 100644 --- a/aliyun/log/index_config.pyi +++ b/aliyun/log/index_config.pyi @@ -17,7 +17,9 @@ class IndexKeyConfig(object): def from_json(self, json_value: Any) -> None: ... class IndexLineConfig(object): - def __init__(self, token_list: Optional[List[str]] = ..., case_sensitive: bool = ..., include_keys: Optional[List[str]] = ..., exclude_keys: Optional[List[str]] = ..., chinese: Optional[bool] = ..., auto_key_detect: Optional[bool] = ..., auto_key_count_limit: Optional[int] = ...) -> None: ... + auto_key_detect: Optional[bool] + auto_text_keys: List[str] + def __init__(self, token_list: Optional[List[str]] = ..., case_sensitive: bool = ..., include_keys: Optional[List[str]] = ..., exclude_keys: Optional[List[str]] = ..., chinese: Optional[bool] = ..., auto_key_detect: Optional[bool] = ..., auto_key_count_limit: Optional[int] = ..., auto_text_keys: Optional[List[str]] = ...) -> None: ... def to_json(self) -> Any: ... def from_json(self, json_value: Any) -> None: ... diff --git a/aliyun/log/version.py b/aliyun/log/version.py index a9fea62..c802b19 100644 --- a/aliyun/log/version.py +++ b/aliyun/log/version.py @@ -1,4 +1,4 @@ -__version__ = '0.9.51' +__version__ = '0.9.52' import sys OS_VERSION = str(sys.platform) diff --git a/tests/ci/build-test/test_index_config.py b/tests/ci/build-test/test_index_config.py new file mode 100644 index 0000000..f41c844 --- /dev/null +++ b/tests/ci/build-test/test_index_config.py @@ -0,0 +1,67 @@ +import json + +from aliyun.log import IndexConfig, IndexLineConfig, LogClient + + +def test_auto_index_defaults_and_legacy_response(): + line = IndexLineConfig() + assert line.auto_key_detect is False + assert line.auto_text_keys == [] + assert line.to_json()['auto_key_detect'] is False + assert line.to_json()['auto_text_keys'] == [] + line.auto_key_detect = True + line.auto_text_keys.append('host') + assert IndexLineConfig().auto_text_keys == [] + line.from_json({'token': [',', ' ']}) + assert line.auto_key_detect is False + assert line.auto_text_keys == [] + + +def test_auto_index_create_get_update(monkeypatch): + client = LogClient('cn-mock.example.com', 'mock-id', 'mock-key') + requests = [] + returned_line = { + 'token': [',', ' '], 'caseSensitive': False, + 'auto_key_detect': True, 'auto_text_keys': ['host', 'request_id', 'latency'], + } + + def send(method, project, body, resource, params, headers): + assert project == 'my-project' + assert resource == '/logstores/my-logs/index' + if method == 'GET': + return {'line': returned_line}, {} + requests.append((method, json.loads(body.decode('utf-8')))) + return {}, {} + + monkeypatch.setattr(client, '_send', send) + line = IndexLineConfig(token_list=[',', ' '], auto_key_detect=True, + auto_text_keys=['host', 'request_id', 'latency']) + client.create_index('my-project', 'my-logs', IndexConfig(line_config=line)) + config = client.get_index_config('my-project', 'my-logs').get_index_config() + assert config.line_config.auto_key_detect is True + assert config.line_config.auto_text_keys == returned_line['auto_text_keys'] + config.line_config.case_sensitive = True + client.update_index('my-project', 'my-logs', config) + config.line_config.auto_text_keys = ['host'] + client.update_index('my-project', 'my-logs', config) + config.line_config.auto_text_keys = [] + client.update_index('my-project', 'my-logs', config) + + assert [method for method, body in requests] == ['POST', 'PUT', 'PUT', 'PUT'] + assert requests[0][1]['line']['auto_key_detect'] is True + assert requests[0][1]['line']['auto_text_keys'] == returned_line['auto_text_keys'] + assert requests[1][1]['line']['auto_text_keys'] == returned_line['auto_text_keys'] + assert requests[1][1]['line']['caseSensitive'] is True + assert requests[2][1]['line']['auto_text_keys'] == ['host'] + assert requests[3][1]['line']['auto_text_keys'] == [] + + +def test_auto_index_preserves_existing_optional_arguments(): + line = IndexLineConfig([], False, None, None, False, True, 100, ['host']) + assert line.to_json()['auto_key_count_limit'] == 100 + assert line.to_json()['auto_text_keys'] == ['host'] + line.auto_key_detect = False + assert 'auto_key_count_limit' not in line.to_json() + assert line.to_json()['auto_text_keys'] == ['host'] + line.auto_key_detect = None + assert 'auto_key_detect' not in line.to_json() From 66721457610d601bc6378a07ce2bd36c6c433b07 Mon Sep 17 00:00:00 2001 From: crimson-gao <1291463831@qq.com> Date: Tue, 15 Sep 2026 16:43:22 +0800 Subject: [PATCH 2/4] test: cover index fields with auto discovery disabled --- HISTORY.md | 2 +- aliyun/log/index_config.py | 2 ++ tests/ci/build-test/test_index_config.py | 13 ++++++++----- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index b98a454..2c45f42 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -4,7 +4,7 @@ **Feature** -- support auto_text_keys in index creation, updates and responses, with auto_key_detect defaulting to False and auto_text_keys to an empty list. Updates replace the full auto_text_keys list; preserve existing fields when changing other index settings. +- support auto_text_keys in index creation, updates and responses, with auto_key_detect defaulting to False and auto_text_keys to an empty list. The field list remains effective when auto discovery is disabled. Updates replace the full auto_text_keys list; preserve existing fields when changing other index settings. ## 0.9.51 (2026-09-07) diff --git a/aliyun/log/index_config.py b/aliyun/log/index_config.py index 32bd35f..1828bb7 100755 --- a/aliyun/log/index_config.py +++ b/aliyun/log/index_config.py @@ -197,6 +197,8 @@ class IndexLineConfig(object): :type auto_text_keys: string list :param auto_text_keys: automatically discovered text fields, defaults to an empty list. + Fields remain effective when auto_key_detect is False; disabling detection + only stops new fields from being discovered. Fields reuse the line token and case-sensitivity settings. Updates replace the complete list; preserve existing fields when changing other index settings. To use a numeric type or custom settings, move the field to explicit keys diff --git a/tests/ci/build-test/test_index_config.py b/tests/ci/build-test/test_index_config.py index f41c844..f955938 100644 --- a/tests/ci/build-test/test_index_config.py +++ b/tests/ci/build-test/test_index_config.py @@ -1,5 +1,7 @@ import json +import pytest + from aliyun.log import IndexConfig, IndexLineConfig, LogClient @@ -17,12 +19,13 @@ def test_auto_index_defaults_and_legacy_response(): assert line.auto_text_keys == [] -def test_auto_index_create_get_update(monkeypatch): +@pytest.mark.parametrize('auto_key_detect', [True, False]) +def test_auto_index_create_get_update(monkeypatch, auto_key_detect): client = LogClient('cn-mock.example.com', 'mock-id', 'mock-key') requests = [] returned_line = { 'token': [',', ' '], 'caseSensitive': False, - 'auto_key_detect': True, 'auto_text_keys': ['host', 'request_id', 'latency'], + 'auto_key_detect': auto_key_detect, 'auto_text_keys': ['host', 'request_id', 'latency'], } def send(method, project, body, resource, params, headers): @@ -34,11 +37,11 @@ def send(method, project, body, resource, params, headers): return {}, {} monkeypatch.setattr(client, '_send', send) - line = IndexLineConfig(token_list=[',', ' '], auto_key_detect=True, + line = IndexLineConfig(token_list=[',', ' '], auto_key_detect=auto_key_detect, auto_text_keys=['host', 'request_id', 'latency']) client.create_index('my-project', 'my-logs', IndexConfig(line_config=line)) config = client.get_index_config('my-project', 'my-logs').get_index_config() - assert config.line_config.auto_key_detect is True + assert config.line_config.auto_key_detect is auto_key_detect assert config.line_config.auto_text_keys == returned_line['auto_text_keys'] config.line_config.case_sensitive = True client.update_index('my-project', 'my-logs', config) @@ -48,7 +51,7 @@ def send(method, project, body, resource, params, headers): client.update_index('my-project', 'my-logs', config) assert [method for method, body in requests] == ['POST', 'PUT', 'PUT', 'PUT'] - assert requests[0][1]['line']['auto_key_detect'] is True + assert all(body['line']['auto_key_detect'] is auto_key_detect for method, body in requests) assert requests[0][1]['line']['auto_text_keys'] == returned_line['auto_text_keys'] assert requests[1][1]['line']['auto_text_keys'] == returned_line['auto_text_keys'] assert requests[1][1]['line']['caseSensitive'] is True From db68f8938877da1884aea48fcb32a38c6fb0a123 Mon Sep 17 00:00:00 2001 From: crimson-gao <1291463831@qq.com> Date: Tue, 15 Sep 2026 17:13:25 +0800 Subject: [PATCH 3/4] docs: clarify automatic field index semantics --- HISTORY.md | 2 ++ aliyun/log/index_config.py | 12 +++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 2c45f42..41fa9e4 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -6,6 +6,8 @@ - support auto_text_keys in index creation, updates and responses, with auto_key_detect defaulting to False and auto_text_keys to an empty list. The field list remains effective when auto discovery is disabled. Updates replace the full auto_text_keys list; preserve existing fields when changing other index settings. +- keys in auto_text_keys are treated as automatically discovered text field indexes with statistical analysis enabled; tokenization and case sensitivity inherit the full-text index settings. + ## 0.9.51 (2026-09-07) **Breaking Changes** diff --git a/aliyun/log/index_config.py b/aliyun/log/index_config.py index 1828bb7..de08c84 100755 --- a/aliyun/log/index_config.py +++ b/aliyun/log/index_config.py @@ -196,11 +196,13 @@ class IndexLineConfig(object): :param auto_key_count_limit: limit for auto key count, only effective when auto_key_detect is True :type auto_text_keys: string list - :param auto_text_keys: automatically discovered text fields, defaults to an empty list. - Fields remain effective when auto_key_detect is False; disabling detection - only stops new fields from being discovered. - Fields reuse the line token and case-sensitivity settings. Updates replace the - complete list; preserve existing fields when changing other index settings. + :param auto_text_keys: keys treated as automatically discovered text field indexes, + defaults to an empty list. Statistical analysis is enabled for these field + indexes. Tokenization and case sensitivity inherit the full-text (line) + index settings. Fields remain effective when auto_key_detect is False; + disabling detection only stops new fields from being discovered. + Updates replace the complete list; preserve existing fields when changing + other index settings. To use a numeric type or custom settings, move the field to explicit keys and remove it from this list. From 1f878ca0ec4e986f5d475ebd6cd9f4e30717b66c Mon Sep 17 00:00:00 2001 From: crimson-gao <1291463831@qq.com> Date: Tue, 15 Sep 2026 17:14:36 +0800 Subject: [PATCH 4/4] docs: clarify field retention after disabling discovery --- HISTORY.md | 2 +- aliyun/log/index_config.py | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 41fa9e4..47e5536 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -4,7 +4,7 @@ **Feature** -- support auto_text_keys in index creation, updates and responses, with auto_key_detect defaulting to False and auto_text_keys to an empty list. The field list remains effective when auto discovery is disabled. Updates replace the full auto_text_keys list; preserve existing fields when changing other index settings. +- support auto_text_keys in index creation, updates and responses, with auto_key_detect defaulting to False and auto_text_keys to an empty list. Disabling auto discovery retains the existing auto_text_keys unless explicitly cleared. Updates replace the full auto_text_keys list; preserve existing fields when changing other index settings. - keys in auto_text_keys are treated as automatically discovered text field indexes with statistical analysis enabled; tokenization and case sensitivity inherit the full-text index settings. diff --git a/aliyun/log/index_config.py b/aliyun/log/index_config.py index de08c84..f4025df 100755 --- a/aliyun/log/index_config.py +++ b/aliyun/log/index_config.py @@ -199,12 +199,10 @@ class IndexLineConfig(object): :param auto_text_keys: keys treated as automatically discovered text field indexes, defaults to an empty list. Statistical analysis is enabled for these field indexes. Tokenization and case sensitivity inherit the full-text (line) - index settings. Fields remain effective when auto_key_detect is False; - disabling detection only stops new fields from being discovered. - Updates replace the complete list; preserve existing fields when changing - other index settings. - To use a numeric type or custom settings, move the field to explicit keys - and remove it from this list. + index settings. Disabling auto_key_detect stops discovery of new fields; + existing auto_text_keys remain effective and are retained unless explicitly + cleared. Updates replace the complete list; preserve existing fields when + changing other index settings. """