Skip to content

Commit

Permalink
Add support for constant_keyword's 'value' parameter (elastic#1112)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Martin committed Nov 18, 2020
1 parent 27fe7e0 commit 2c56909
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions scripts/generators/es_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
22 changes: 22 additions & 0 deletions scripts/tests/test_es_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 2c56909

Please sign in to comment.