Elastic search 如何分析 URL 的 / 带有 '-' 的单词
Elastic search how to analyze URL's / words with '-' in them
我正在尝试找出一种方法来分析 words/URLS 中带有“-”的内容。前任。 "nnn999-9-prod-nnn9.test.com" | "Cisco-NX-4")。
这意味着 "nnn999-" 不会匹配任何内容,但 "nnn999" 或 "nnn999-*" 会匹配,但我希望 "nnn999-" 也匹配。
我已经尝试过标准分析器和 "uax_url_email" 分词器,但两者都以相同的方式解析它,给出相同的标记 ["nnn999", "9", "prod", "nnn9" , "test.com"]。我最不想做的是为每个属性 (10+) 使用正则表达式创建自定义分析器。
非常感谢您的帮助!
从文档中我们可以有效地假设这对你的情况有效,但它不是:(
whitespace tokenizer 可以为您完成这项工作吗?
GET _analyze
{
"tokenizer" : "whitespace",
"text" : "Cisco-NX-4 noise1 noise2 nnn999-9-prod-nnn9.test.com"
}
=>
{
"tokens": [
{
"token": "Cisco-NX-4",
"start_offset": 0,
"end_offset": 10,
"type": "word",
"position": 0
},
{
"token": "noise1",
"start_offset": 11,
"end_offset": 17,
"type": "word",
"position": 1
},
{
"token": "noise2",
"start_offset": 18,
"end_offset": 24,
"type": "word",
"position": 2
},
{
"token": "nnn999-9-prod-nnn9.test.com",
"start_offset": 25,
"end_offset": 52,
"type": "word",
"position": 3
}
]
}
开箱即用,使用默认映射,您的示例应该可以工作。它将对索引和查询使用相同的标准分析器,因此您对 "nnn999-" 的查询将转换为 "nnn999"。例如:
存储文档
POST my-index/_doc
{
"test": "nnn999-9-prod-nnn9.test.com"
}
搜索文档
GET my-index/_search
{
"query": { "match": { "test": "nnn999-" } }
}
结果
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.2876821,
"hits": [
{
"_index": "my-index",
"_type": "_doc",
"_id": "YXnNhGQBFtPd4lycLFbR",
"_score": 0.2876821,
"_source": {
"test": "nnn999-9-prod-nnn9.test.com"
}
}
]
}
}
查看您的索引映射会很有用。
我正在尝试找出一种方法来分析 words/URLS 中带有“-”的内容。前任。 "nnn999-9-prod-nnn9.test.com" | "Cisco-NX-4")。
这意味着 "nnn999-" 不会匹配任何内容,但 "nnn999" 或 "nnn999-*" 会匹配,但我希望 "nnn999-" 也匹配。
我已经尝试过标准分析器和 "uax_url_email" 分词器,但两者都以相同的方式解析它,给出相同的标记 ["nnn999", "9", "prod", "nnn9" , "test.com"]。我最不想做的是为每个属性 (10+) 使用正则表达式创建自定义分析器。
非常感谢您的帮助!
从文档中我们可以有效地假设这对你的情况有效,但它不是:(
whitespace tokenizer 可以为您完成这项工作吗?
GET _analyze
{
"tokenizer" : "whitespace",
"text" : "Cisco-NX-4 noise1 noise2 nnn999-9-prod-nnn9.test.com"
}
=>
{
"tokens": [
{
"token": "Cisco-NX-4",
"start_offset": 0,
"end_offset": 10,
"type": "word",
"position": 0
},
{
"token": "noise1",
"start_offset": 11,
"end_offset": 17,
"type": "word",
"position": 1
},
{
"token": "noise2",
"start_offset": 18,
"end_offset": 24,
"type": "word",
"position": 2
},
{
"token": "nnn999-9-prod-nnn9.test.com",
"start_offset": 25,
"end_offset": 52,
"type": "word",
"position": 3
}
]
}
开箱即用,使用默认映射,您的示例应该可以工作。它将对索引和查询使用相同的标准分析器,因此您对 "nnn999-" 的查询将转换为 "nnn999"。例如:
存储文档
POST my-index/_doc
{
"test": "nnn999-9-prod-nnn9.test.com"
}
搜索文档
GET my-index/_search
{
"query": { "match": { "test": "nnn999-" } }
}
结果
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.2876821,
"hits": [
{
"_index": "my-index",
"_type": "_doc",
"_id": "YXnNhGQBFtPd4lycLFbR",
"_score": 0.2876821,
"_source": {
"test": "nnn999-9-prod-nnn9.test.com"
}
}
]
}
}
查看您的索引映射会很有用。