gpt4 book ai didi

ElasticSearch 搜索部分url

转载 作者:行者123 更新时间:2023-12-02 22:19:21 25 4
gpt4 key购买 nike

我正在使用 ElasticSearch 5,但找不到针对以下问题的解决方案:我想在文档中搜索带有斜线(url 的一部分)的字符串。但它不会返回匹配的文档。我读过一些东西,其中带有斜线的字符串被 ES 分割,这不是我想要的这个字段。我尝试使用映射在字段上设置“not_analyzed”,但我似乎无法以某种方式让它工作。

“创建索引”:放http://localhost:9200/test

{
"settings" : {
"number_of_shards" : 1
},
"mappings" : {
"type1" : {
"properties" : {
"field1" : { "type" : "text","index": "not_analyzed" }
}
}
}
}

“添加文档”:POST http://localhost:9200/test/type1/

{
"field1" : "this/is/a/url/test"
}

“搜索文档”POST http://localhost:9200/test/type1/_search

{
"size" : 1000,
"query" : {
"bool" : {
"must" : [{
"term" : {
"field1" : {
"value" : "this/is/a/url/test"
}
}
}
]
}
}
}

响应:

{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}

“映射响应”:GET http://localhost:9200/test/_mapping?pretty

{
"test": {
"mappings": {
"type1": {
"properties": {
"field1": {
"type": "text"
}
}
}
}
}
}

最佳答案

使用 term 查询来获得精确匹配是正确的。但是,您的初始映射是错误的。

"type" : "text", "index": "not_analyzed"

应该是这个

"type": "keyword"

(注意:ES5 中的 keyword 类型等同于 ES 2.x 中的 not_analyzed string)

您需要删除索引并使用更正的映射重新创建它。然后您的 term 查询将起作用。

关于ElasticSearch 搜索部分url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40932873/

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