Skip to content
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

[1.x] Add fallback for constant_keyword (#1046) #1056

Merged
merged 1 commit into from
Oct 28, 2020
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.next.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Thanks, you're awesome :-) -->

* Added the `path` key when type is `alias`, to support the [alias field type](https://www.elastic.co/guide/en/elasticsearch/reference/current/alias.html). #877
* Added support for `scaled_float`'s mandatory parameter `scaling_factor`. #1042
* Added ability for --oss flag to fall back `constant_keyword` to `keyword`. #1046

#### Improvements

Expand Down
6 changes: 4 additions & 2 deletions scripts/schema/oss.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from schema import visitor

TYPE_FALLBACKS = {
'constant_keyword': 'keyword',
'wildcard': 'keyword',
'version': 'keyword'
}
Expand All @@ -25,5 +26,6 @@ def fallback(fields):

def perform_fallback(field):
"""Performs a best effort fallback of basic data types to equivalent OSS data types."""
if field['field_details']['type'] in TYPE_FALLBACKS.keys():
field['field_details']['type'] = TYPE_FALLBACKS[field['field_details']['type']]
fallback_type = TYPE_FALLBACKS.get(field['field_details']['type'])
if fallback_type:
field['field_details']['type'] = fallback_type
11 changes: 10 additions & 1 deletion scripts/tests/unit/test_schema_oss.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class TestSchemaOss(unittest.TestCase):
def setUp(self):
self.maxDiff = None

# Fallbacks

def test_wildcard_fallback(self):
field = {'field_details': {'name': 'myfield', 'type': 'wildcard'}}
oss.perform_fallback(field)
Expand All @@ -24,12 +26,19 @@ def test_version_fallback(self):
oss.perform_fallback(field)
self.assertEqual('keyword', field['field_details']['type'])

def test_constant_keyword_fallback(self):
field = {'field_details': {'name': 'myfield', 'type': 'constant_keyword'}}
oss.perform_fallback(field)
self.assertEqual('keyword', field['field_details']['type'])

# Not falling back

def test_basic_without_fallback(self):
field = {'field_details': {'name': 'myfield', 'type': 'histogram'}}
oss.perform_fallback(field)
self.assertEqual('histogram', field['field_details']['type'])

def test_oss_no_fallback(self):
def test_oss_no_fallback_needed(self):
field = {'field_details': {'name': 'myfield', 'type': 'keyword'}}
oss.perform_fallback(field)
self.assertEqual('keyword', field['field_details']['type'])