gpt4 book ai didi

java - ElasticSearch查询匹配不正确

转载 作者:行者123 更新时间:2023-12-02 22:54:13 24 4
gpt4 key购买 nike

我试图匹配基于URL字段的查询。我下面有一个我的InsertLink方法,当有人在网页上添加新链接时,该方法将被关闭。现在,如果要添加任何前缀为“https://”或“http://”的链接,它将自动将第一个(在这种情况下)与https://匹配的项
或索引中的“http://”前缀。这是因为我的模型以Uri类型设置的方式吗?这是我的模型的示例,以及用于InsertLink方法的调试的屏幕截图。

我的模特:

public class SSOLink
{
public string Name { get; set; }
public Uri Url { get; set; }
public string Owner { get; set; }

}

屏幕截图的示例。

ElasticSearch Debug

最佳答案

您需要使用UAX_URL tokenizer来搜索URL字段。

您可以使用UAX_URL token 创建您的自定义分析器,并使用与现在为止相同的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字段生成的 token 。

使用标准分析仪
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"
}

并生成 token
{
"tokens": [
{
"token": "https://www.microsoft.com",
"start_offset": 0,
"end_offset": 25,
"type": "<URL>",
"position": 0
}
]
}

关于java - ElasticSearch查询匹配不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60818364/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com