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

Set strings to be keywords by default #2688

Merged
merged 1 commit into from
Oct 5, 2016
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
2 changes: 2 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ https://github.com/elastic/beats/compare/v5.0.0-beta1...master[Check the HEAD di

*Affecting all Beats*

- A dynamic mapping rule is added to the default Elasticsearch template to treat strings as keywords by default. {pull}2688[2688]

*Metricbeat*

*Packetbeat*
Expand Down
5 changes: 2 additions & 3 deletions filebeat/filebeat.template-es2x.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
},
"dynamic_templates": [
{
"fields": {
"strings_as_keyword": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice that you gave it a name. Makes it much more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it used to be the name of the dict/list field name. Now if everything is a keyword by default, the template also gets shorter, because we don't have dicts or lists of type text.

"mapping": {
"ignore_above": 1024,
"index": "not_analyzed",
"type": "string"
},
"match_mapping_type": "string",
"path_match": "fields.*"
"match_mapping_type": "string"
}
}
],
Expand Down
5 changes: 2 additions & 3 deletions filebeat/filebeat.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
},
"dynamic_templates": [
{
"fields": {
"strings_as_keyword": {
"mapping": {
"ignore_above": 1024,
"type": "keyword"
},
"match_mapping_type": "string",
"path_match": "fields.*"
"match_mapping_type": "string"
}
}
],
Expand Down
34 changes: 28 additions & 6 deletions libbeat/scripts/generate_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,30 @@ def fields_to_es_template(args, input, output, index, version):

properties = {}
dynamic_templates = []

# Make strings keywords by default
if args.es2x:
dynamic_templates.append({
"strings_as_keyword": {
"mapping": {
"type": "string",
"index": "not_analyzed",
"ignore_above": 1024
},
"match_mapping_type": "string",
}
})
else:
dynamic_templates.append({
"strings_as_keyword": {
"mapping": {
"type": "keyword",
"ignore_above": 1024
},
"match_mapping_type": "string",
}
})

for section in docs["fields"]:
prop, dynamic = fill_section_properties(args, section,
defaults, "")
Expand Down Expand Up @@ -200,9 +224,9 @@ def fill_field_properties(args, field, defaults, path):
field.get("scaling_factor", 1000)

elif field["type"] in ["dict", "list"]:
if field.get("dict-type") == "keyword":
if field.get("dict-type") == "text":
# add a dynamic template to set all members of
# the dict as keywords
# the dict as text
if len(path) > 0:
name = path + "." + field["name"]
else:
Expand All @@ -213,8 +237,7 @@ def fill_field_properties(args, field, defaults, path):
name: {
"mapping": {
"type": "string",
"index": "not_analyzed",
"ignore_above": 1024
"index": "analyzed",
},
"match_mapping_type": "string",
"path_match": name + ".*"
Expand All @@ -224,8 +247,7 @@ def fill_field_properties(args, field, defaults, path):
dynamic_templates.append({
name: {
"mapping": {
"type": "keyword",
"ignore_above": 1024
"type": "text",
},
"match_mapping_type": "string",
"path_match": name + ".*"
Expand Down
5 changes: 2 additions & 3 deletions metricbeat/metricbeat.template-es2x.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
},
"dynamic_templates": [
{
"fields": {
"strings_as_keyword": {
"mapping": {
"ignore_above": 1024,
"index": "not_analyzed",
"type": "string"
},
"match_mapping_type": "string",
"path_match": "fields.*"
"match_mapping_type": "string"
}
}
],
Expand Down
5 changes: 2 additions & 3 deletions metricbeat/metricbeat.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
},
"dynamic_templates": [
{
"fields": {
"strings_as_keyword": {
"mapping": {
"ignore_above": 1024,
"type": "keyword"
},
"match_mapping_type": "string",
"path_match": "fields.*"
"match_mapping_type": "string"
}
}
],
Expand Down
49 changes: 2 additions & 47 deletions packetbeat/packetbeat.template-es2x.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,58 +11,13 @@
},
"dynamic_templates": [
{
"fields": {
"strings_as_keyword": {
"mapping": {
"ignore_above": 1024,
"index": "not_analyzed",
"type": "string"
},
"match_mapping_type": "string",
"path_match": "fields.*"
}
},
{
"amqp.headers": {
"mapping": {
"ignore_above": 1024,
"index": "not_analyzed",
"type": "string"
},
"match_mapping_type": "string",
"path_match": "amqp.headers.*"
}
},
{
"cassandra.response.supported": {
"mapping": {
"ignore_above": 1024,
"index": "not_analyzed",
"type": "string"
},
"match_mapping_type": "string",
"path_match": "cassandra.response.supported.*"
}
},
{
"http.request.headers": {
"mapping": {
"ignore_above": 1024,
"index": "not_analyzed",
"type": "string"
},
"match_mapping_type": "string",
"path_match": "http.request.headers.*"
}
},
{
"http.response.headers": {
"mapping": {
"ignore_above": 1024,
"index": "not_analyzed",
"type": "string"
},
"match_mapping_type": "string",
"path_match": "http.response.headers.*"
"match_mapping_type": "string"
}
}
],
Expand Down
45 changes: 2 additions & 43 deletions packetbeat/packetbeat.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,12 @@
},
"dynamic_templates": [
{
"fields": {
"strings_as_keyword": {
"mapping": {
"ignore_above": 1024,
"type": "keyword"
},
"match_mapping_type": "string",
"path_match": "fields.*"
}
},
{
"amqp.headers": {
"mapping": {
"ignore_above": 1024,
"type": "keyword"
},
"match_mapping_type": "string",
"path_match": "amqp.headers.*"
}
},
{
"cassandra.response.supported": {
"mapping": {
"ignore_above": 1024,
"type": "keyword"
},
"match_mapping_type": "string",
"path_match": "cassandra.response.supported.*"
}
},
{
"http.request.headers": {
"mapping": {
"ignore_above": 1024,
"type": "keyword"
},
"match_mapping_type": "string",
"path_match": "http.request.headers.*"
}
},
{
"http.response.headers": {
"mapping": {
"ignore_above": 1024,
"type": "keyword"
},
"match_mapping_type": "string",
"path_match": "http.response.headers.*"
"match_mapping_type": "string"
}
}
],
Expand Down
27 changes: 2 additions & 25 deletions winlogbeat/winlogbeat.template-es2x.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,13 @@
},
"dynamic_templates": [
{
"fields": {
"strings_as_keyword": {
"mapping": {
"ignore_above": 1024,
"index": "not_analyzed",
"type": "string"
},
"match_mapping_type": "string",
"path_match": "fields.*"
}
},
{
"event_data": {
"mapping": {
"ignore_above": 1024,
"index": "not_analyzed",
"type": "string"
},
"match_mapping_type": "string",
"path_match": "event_data.*"
}
},
{
"user_data": {
"mapping": {
"ignore_above": 1024,
"index": "not_analyzed",
"type": "string"
},
"match_mapping_type": "string",
"path_match": "user_data.*"
"match_mapping_type": "string"
}
}
],
Expand Down
25 changes: 2 additions & 23 deletions winlogbeat/winlogbeat.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,12 @@
},
"dynamic_templates": [
{
"fields": {
"strings_as_keyword": {
"mapping": {
"ignore_above": 1024,
"type": "keyword"
},
"match_mapping_type": "string",
"path_match": "fields.*"
}
},
{
"event_data": {
"mapping": {
"ignore_above": 1024,
"type": "keyword"
},
"match_mapping_type": "string",
"path_match": "event_data.*"
}
},
{
"user_data": {
"mapping": {
"ignore_above": 1024,
"type": "keyword"
},
"match_mapping_type": "string",
"path_match": "user_data.*"
"match_mapping_type": "string"
}
}
],
Expand Down