您需要使用UAX_URL 标记器来搜索 URL 字段。
您可以使用 UAX_URL 令牌创建自定义分析器,并使用match
您现在使用的相同查询来获得预期结果。
索引映射
{
"settings": {
"analysis": {
"analyzer": {
"my_analyzer": {
"tokenizer": "my_tokenizer"
}
},
"tokenizer": {
"my_tokenizer": {
"type": "uax_url_email",
"max_token_length": 5
}
}
}
},
"mappings": {
"properties": {
"url": {
"type": "text",
"analyzer": "my_analyzer"
}
}
}
}
看起来在您的情况下,URL 字段正在使用 Elasticsearch 中的文本字段,它使用标准分析器并使用 _analyze API,您可以检查 URL 字段生成的令牌。
使用标准分析仪
POST _analyze/
{
"text": "https://www.microsoft.com",
"analyzer" : "standard"
}
代币
{
"tokens": [
{
"token": "https",
"start_offset": 0,
"end_offset": 5,
"type": "<ALPHANUM>",
"position": 0
},
{
"token": "www.microsoft.com",
"start_offset": 8,
"end_offset": 25,
"type": "<ALPHANUM>",
"position": 1
}
]
}
使用 UAX_URL 标记器
{
"text": "https://www.microsoft.com",
"tokenizer" : "uax_url_email"
}
并生成令牌
{
"tokens": [
{
"token": "https://www.microsoft.com",
"start_offset": 0,
"end_offset": 25,
"type": "<URL>",
"position": 0
}
]
}