fanybook
(fanybook)
May 11, 2022, 9:26am
1
filebeat version: 7.17.3
json 模板是这样的
{
"index_patterns": ["test_logs*"],
"template": {
"settings": {
"number_of_shards": 1
},
"mappings": {
"properties": {
"message123": {
"type": "text",
"analyzer": "ik_max_word"
},
"level123": {
"type": "keyword"
}
}
},
"aliases": {}
}
}
但是生成的索引里,message123 字段没有 analyzer,level123字段的类型也不对
{
"version": 4,
"mapping_version": 2,
"settings_version": 1,
"aliases_version": 1,
"routing_num_shards": 1024,
"state": "open",
"settings": {
"index": {
"creation_date": "1652257343314",
"number_of_shards": "1",
"number_of_replicas": "1",
"uuid": "Aut0taBNSFqe0oH0tR_hIQ",
"version": {
"created": "7080199"
},
"provided_name": "test_logs"
}
},
"mappings": {
"_doc": {
"properties": {
"@timestamp": {
"type": "date"
},
"message123": {
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
},
"log": {
"properties": {
"file": {
"properties": {
"path": {
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
}
}
},
"offset": {
"type": "long"
}
}
},
"level123": {
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
}
}
}
},
"aliases": [],
"primary_terms": {
"0": 1
},
"in_sync_allocations": {
"0": [
"Sesp4gsmSRCSHxG6nJPX5w"
]
},
"rollover_info": {}
}
网上有教程说改 fields.yml,但 GitHub 上,明显还不支持这么做,貌似 8.1 才可以
elastic:master
← efd6:libbeat/inlineanalyzer
opened 05:39AM - 11 Nov 21 UTC
<!-- Type of change
Please label this PR with one of the following labels, depe… nding on the scope of your change:
- Bug
- Enhancement
- Breaking change
- Deprecation
- Cleanup
- Docs
-->
## What does this PR do?
<!-- Mandatory
Explain here the changes you made on the PR. Please explain the WHAT: patterns used, algorithms implemented, design architecture, message processing, etc.
-->
This adds support for defining custom text analyzers in fields.yml files. For example:
```
- key: powershell
title: PowerShell module
description: >
These are the event fields specific to the module for the Microsoft-Windows-PowerShell/Operational and Windows PowerShell logs.
release: beta
analyzer:
powershell_script_analyzer:
type: pattern
pattern: "[\\W&&[^-]]+"
fields:
...
```
## Why is it important?
<!-- Mandatory
Explain here the WHY, or the rationale/motivation for the changes.
-->
Not being able to define custom analyzers is a blocker for processing some documents containing syntactically meaningful non-standard token structures (for example captured script text as shown above).
## Checklist
<!-- Mandatory
Add a checklist of things that are required to be reviewed in order to have the PR approved
List here all the items you have verified BEFORE sending this PR. Please DO NOT remove any item, striking through those that do not apply. (Just in case, strikethrough uses two tildes. ~~Scratch this.~~)
-->
- [x] My code follows the style guidelines of this project
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
~~- [ ] I have made corresponding change to the default configuration files~~
- [x] I have added tests that prove my fix is effective or that my feature works
- [x] I have added an entry in `CHANGELOG.next.asciidoc` or `CHANGELOG-developer.next.asciidoc`.
## Author's Checklist
<!-- Recommended
Add a checklist of things that are required to be reviewed in order to have the PR approved
-->
No specific recommendations.
## How to test this PR locally
<!-- Recommended
Explain here how this PR will be tested by the reviewer: commands, dependencies, steps, etc.
-->
Running `go test` in the relevant packages tests this change.
## Related issues
<!-- Recommended
Link related issues below. Insert the issue link or reference after the word "Closes" if merging this should automatically close it.
- Closes #123
- Relates #123
- Requires #123
- Superseds #123
-->
- Closes #28540
- Relates #28483
- Relates elastic/integrations#1931
## Use cases
<!-- Recommended
Explain here the different behaviors that this PR introduces or modifies in this project, user roles, environment configuration, etc.
If you are familiar with Gherkin test scenarios, we recommend its usage: https://cucumber.io/docs/gherkin/reference/
-->
Use case is shown above.
## Screenshots
<!-- Optional
Add here screenshots about how the project will be changed after the PR is applied. They could be related to web pages, terminal, etc, or any other image you consider important to be shared with the team.
-->
N/A
## Logs
<!-- Recommended
Paste here output logs discovered while creating this PR, such as stack traces or integration logs, or any other output you consider important to be shared with the team.
-->
N/A
martinliu
(Martin Liu)
May 11, 2022, 11:07am
2
尝试下这个做法,在摄入日志前,先做 filebeat setup ; 在 setup 完了以后,在修改 filebeat 的索引 mapping ,加入你需要的 analyzer,
也可以通过修改 fields.yml 的方式在修改 mapping 设置,加上你所需要的。7.17 应该是 ok 的。
fanybook
(fanybook)
May 12, 2022, 2:58am
3
感谢帮助
我大概试了一下您说的:
我关闭了 json 模板(不关就不会走 fields.yml),去修改 fields.yml,并没有得到我想要
fields.yml,注意:一个 text 类型,一个 keyword 类型
- name: message123
level: core
type: text
description: 'one message.'
example: Hello World
- name: level123
level: core
type: keyword
description: 'one level.'
example: error
我得到的索引类型:两个都是 keyword 类型
{
"message123": {
"ignore_above": 1024,
"type": "keyword"
},
"level123": {
"ignore_above": 1024,
"type": "keyword"
}
}
手动使用 filebeat setup,这种方式能说的再清晰一些么?我做了这个,但完全没有作用
./filebeat setup --index-management -E 'output.elasticsearch.hosts=["172.16.100.128:9200"]' -E 'output.elasticsearch.username="elastic"' -E 'output.elasticsearch.password="temppwd"' -E 'setup.template.json.enabled=true' -E 'setup.template.json.path="/opt/filebeat/index/template/golang_logs_index_template.json"' -E 'setup.template.json.name="golang_logs_index_template"'
我知道 filebeat setup 是手动加载索引模板的方法,但是我不知道它是怎么和 ./filebeat -e -c test01.yml 中的 test01.yml 关联的
fanybook
(fanybook)
May 12, 2022, 6:00am
4
我知道原因了,是 json 模板里多了一级 template
system
(system)
Closed
June 9, 2022, 7:31am
6
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.