From 2c56909eaecaae160546b0ac73ecfab6dd0d8801 Mon Sep 17 00:00:00 2001 From: Mathieu Martin Date: Wed, 18 Nov 2020 14:02:15 -0500 Subject: [PATCH] Add support for constant_keyword's 'value' parameter (#1112) --- CHANGELOG.next.md | 1 + scripts/generators/es_template.py | 2 ++ scripts/tests/test_es_template.py | 22 ++++++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/CHANGELOG.next.md b/CHANGELOG.next.md index 8b182475d3..0dcfdfaa7c 100644 --- a/CHANGELOG.next.md +++ b/CHANGELOG.next.md @@ -36,6 +36,7 @@ Thanks, you're awesome :-) --> * Added support for `scaled_float`'s mandatory parameter `scaling_factor`. #1042 * Added ability for --oss flag to fall back `constant_keyword` to `keyword`. #1046 * Added support in the generated Go source go for `wildcard`, `version`, and `constant_keyword` data types. #1050 +* Added support for `constant_keyword`'s optional parameter `value`. #1112 #### Improvements diff --git a/scripts/generators/es_template.py b/scripts/generators/es_template.py index 13498cef9d..086d5246b9 100644 --- a/scripts/generators/es_template.py +++ b/scripts/generators/es_template.py @@ -57,6 +57,8 @@ def entry_for(field): if field['type'] == 'keyword': ecs_helpers.dict_copy_existing_keys(field, field_entry, ['ignore_above']) + elif field['type'] == 'constant_keyword': + ecs_helpers.dict_copy_existing_keys(field, field_entry, ['value']) elif field['type'] == 'text': ecs_helpers.dict_copy_existing_keys(field, field_entry, ['norms']) elif field['type'] == 'alias': diff --git a/scripts/tests/test_es_template.py b/scripts/tests/test_es_template.py index a1491d2241..43ee4d276f 100644 --- a/scripts/tests/test_es_template.py +++ b/scripts/tests/test_es_template.py @@ -135,6 +135,28 @@ def test_entry_for_scaled_float(self): } self.assertEqual(es_template.entry_for(test_map), exp) + def test_constant_keyword_with_value(self): + test_map = { + 'name': 'field_with_value', + 'type': 'constant_keyword', + 'value': 'foo' + } + + exp = { + 'type': 'constant_keyword', + 'value': 'foo' + } + self.assertEqual(es_template.entry_for(test_map), exp) + + def test_constant_keyword_no_value(self): + test_map = { + 'name': 'field_without_value', + 'type': 'constant_keyword' + } + + exp = {'type': 'constant_keyword'} + self.assertEqual(es_template.entry_for(test_map), exp) + if __name__ == '__main__': unittest.main()