诚然,我对ES的分析部分不太熟悉。这是索引布局:
{
"mappings": {
"event": {
"properties": {
"ipaddress": {
"type": "string"
},
"hostname": {
"type": "string",
"analyzer": "my_analyzer",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
},
"settings": {
"analysis": {
"filter": {
"my_filter": {
"type": "word_delimiter",
"preserve_original": true
}
},
"analyzer": {
"my_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": ["lowercase", "my_filter"]
}
}
}
}
}
您可以看到我尝试对主机名字段使用自定义分析器。当我使用此查询查找名为“WIN_1”的主机时,这种方法有效:
{
"query": {
"match": {
"hostname": "WIN_1"
}
}
}
问题是它还会返回任何包含 1 的主机名。使用_analyze
端点,我可以看到数字也被标记化了。
{
"tokens": [
{
"token": "win_1",
"start_offset": 0,
"end_offset": 5,
"type": "word",
"position": 1
},
{
"token": "win",
"start_offset": 0,
"end_offset": 3,
"type": "word",
"position": 1
},
{
"token": "1",
"start_offset": 4,
"end_offset": 5,
"type": "word",
"position": 2
}
]
}
我想要做的是搜索 WIN 并取回名称中包含 WIN 的任何主机。但我还需要能够搜索 WIN_1 并取回该确切的主机或名称中包含 WIN_1 的任何主机。下面是一些测试数据。
{
"ipaddress": "192.168.1.253",
"hostname": "WIN_8_ENT_1"
}
{
"ipaddress": "10.0.0.1",
"hostname": "server1"
}
{
"ipaddress": "172.20.10.36",
"hostname": "ServA-1"
}
希望有人能指出我正确的方向。我的简单查询也可能不是正确的方法。我已经仔细阅读了 ES 文档,但它们的示例并不好。