gpt4 book ai didi

elasticsearch - 模糊查询未给出任何结果

转载 作者:行者123 更新时间:2023-12-02 23:10:42 24 4
gpt4 key购买 nike

flex 搜索中的模糊查询无法正常工作,即使精确值也为空。

ES版本: 7.6.2

索引映射:以下是映射详细信息

{
"movies" : {
"mappings" : {
"properties" : {
"genre" : {
"type" : "text",
"fields" : {
"field" : {
"type" : "keyword"
}
}
},
"id" : {
"type" : "long"
},
"rating" : {
"type" : "double"
},
"title" : {
"type" : "text"
}
}
}
}
}

文档:索引中包含以下文档
    {
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "movies",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"id" : 2,
"title" : "Raju Ban gaya gentleman",
"rating" : 2,
"genre" : [
"Drama"
]
}
},
{
"_index" : "movies",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"id" : 2,
"title" : "Baat ban jaegi gentleman",
"rating" : 4,
"genre" : [
"Drama"
]
}
}
]
}
}

查询:以下是我用于搜索文档的查询
GET movies/_search
{
"query": {
"fuzzy": {
"title": {"value": "Bat ban jaegi gentleman", "fuzziness": 1}
}
}
}

我以前没有使用过模糊查询,据我所知它应该可以正常工作。

最佳答案

不会分析模糊查询,但会在此字段中进行搜索Bat ban jaegi gentleman将被分为不同的术语,并且Bat将被分析,并且该术语将被进一步用于过滤结果。

您也可以引用ElasticSearch's Fuzzy Query这个答案,以了解为什么模糊查询在现场进行分析。

但是,由于您要分析完整的标题,因此可以将title的映射更改为也具有keyword字段。

您可以通过分析API看到如何精确地对您的字符串进行标记:
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-analyze.html

下面是相同的映射:

"mappings": {
"properties": {
"genre": {
"type": "text",
"fields": {
"field": {
"type": "keyword"
}
}
},
"id": {
"type": "long"
},
"rating": {
"type": "double"
},
"title": {
"type": "text",
"fields": {
"field": {
"type": "keyword"
}
}
}
}
}

现在,如果您在title.field上搜索,将获得所需的结果。搜索查询是:
    {
"query": {
"fuzzy": {
"title.field": {"value": "Bat ban jaegi gentleman", "fuzziness": 1}
}
}
}

在这种情况下获得的结果是:
"hits": [
{
"_index": "ftestmovies",
"_type": "_doc",
"_id": "2",
"_score": 0.9381845,
"_source": {
"title": "Baat ban jaegi gentleman",
"rating": 4,
"genre": [
"Drama"
]
}
}
]

关于elasticsearch - 模糊查询未给出任何结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60989561/

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