gpt4 book ai didi

elasticsearch - 为什么这个简单的 Elasticsearch 查询什么都不返回?

转载 作者:行者123 更新时间:2023-12-03 01:51:10 25 4
gpt4 key购买 nike

我想在数据库中搜索URL。我有这样的文件:

    {
"_index": "test",
"_type": "medhelp",
"_id": "AVgPTB_dMXsxewkUBUNN",
"_score": 1,
"_source": {
"title": "Pump minimed 404sp, 506,507,508",
"text": "",
"abstract": "\n I am looking to buy one of these pump for testing purpose. It need to be in working condition. Email me if you have one for sale ***@****\n ",
"answers": [],
"source": "medhelp",
"link": "/posts/Diabetes---Type-1/Pump-minimed-404sp--506-507-508/show/2431714"
}

当我搜索这样的源时,我可以获得结果:
{
"query": {
"prefix": {
"source": "medhelp"
}
}
}

但是,当我尝试对带有URL的“链接”字段执行相同操作时,始终不会返回任何内容。这是怎么回事:
{
"query": {
"prefix": {
"link": "/posts/Diabetes---Type-1/Pump-minimed-404sp--506-507-508/show/2431714"
}
}
}

这是上面查询的结果:
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}

最佳答案

我猜您使用默认的“标准”分析器,因此“链接”的值不会被视为一个整体,而是会被视为许多小片段。

因此,答案是对“链接”字段使用“关键字”分析器。

以下代码是一个如何实现此目标的示例(您可以使用Chrome浏览器的Sense插件一次执行一条指令的代码)。

最重要的是用于“链接”字段映射的“analyzer:关键字”。
如果您删除此行,则将得到您的确切答复。

DELETE /test123
PUT /test123
{
"mappings": {
"medhelp" : {
"properties": {
"link": { "type": "string"
,"analyzer": "keyword"
},
"source": { "type": "string"}
}
}
}
}

GET /test123/_mapping

PUT /test123/medhelp/1
{
"link":"/posts/Diabetes---Type-1/Pump-minimed-404sp--506-507-508/show/2431714",
"source":"medhelp"
}

GET /test123/_search
{
"query": {
"prefix": {
"link": "/posts/Diabetes---Type-1/Pump-minimed-404sp--506-507-508/show/2431714"
}
}
}

关于elasticsearch - 为什么这个简单的 Elasticsearch 查询什么都不返回?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40327229/

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