gpt4 book ai didi

mongodb - ElasticSearch自动完成返回0次

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

我正在尝试为我们在MongoDB上运行的数据库构建自动完成功能。我们需要提供自动完成功能,以便用户在搜索框中键入内容时提供建议,从而完成查询。

我从各种来源收集了articles,其中包含以下字段:

{
"title" : "Its the title of a random article",
"cont" : { "paragraphs" : [ .... ] },
and so on..
}

我经历了 video by Clinton Gormley。从37:00到42:00分钟,Gormley使用 edgeNGram描述了自动完成功能。另外,我引用 this question来认识到两者几乎是相同的,只是映射不同。

因此,基于这些经验,我建立了几乎相同的设置和映射,然后还原了 articles集合以确保其被ElasticSearch索引

索引方案如下:
POST /title_autocomplete/title
{
"settings": {

"analysis": {
"filter": {
"autocomplete": {
"type": "edgeNGram",
"min_gram": 2,
"max_gram": 50
}
},

"analyzer": {

"title" : {
"type" : "standard",
"stopwords":[]
},
"autocomplete": {
"type" : "autocomplete",
"tokenizer": "standard",
"filter": ["lowercase", "autocomplete"]
}
}
}
},
"mappings": {
"title": {
"type": "multi_field",
"fields" : {
"title" : {
"type": "string",
"analyzer": "title"
},
"autocomplete" : {
"type": "string",
"index_analyzer": "autocomplete",
"search_analyzer" : "title"
}
}
}
}
}

但是,当我运行搜索查询时,我无法获得任何点击!
GET /title_autocomplete/title/_search
{
"query": {
"bool" : {
"must" : {
"match" : {
"title.autocomplete" : "Its the titl"
}
},
"should" : {
"match" : {
"title" : "Its the titl"
}
}
}
}
}

谁能解释映射查询或设置有什么问题吗?我已经阅读ElasticSearch文档超过7天了,但是似乎没有比全文搜索更多的地方了!
  • ElastiSearch版本:0.90.10
  • MongoDB版本:v2.4.9
  • 使用_river
  • Ubuntu 12.04 64位

  • 更新
    我意识到应用先前的设置后,映射就搞砸了:
    GET /title_autocomplete/_mapping
    {
    "title_autocomplete": {
    "title": {
    "properties": {
    "analysis": {
    "properties": {
    "analyzer": {
    "properties": {
    "autocomplete": {
    "properties": {
    "filter": {
    "type": "string"
    },
    "tokenizer": {
    "type": "string"
    },
    "type": {
    "type": "string"
    }
    }
    },
    "title": {
    "properties": {
    "type": {
    "type": "string"
    }
    }
    }
    }
    },
    "filter": {
    "properties": {
    "autocomplete": {
    "properties": {
    "max_gram": {
    "type": "long"
    },
    "min_gram": {
    "type": "long"
    },
    "type": {
    "type": "string"
    }
    }
    }
    }
    }
    }
    },
    "content": {
    ... paras and all ...
    }
    "title": {
    "type": "string"
    },
    "url": {
    "type": "string"
    }
    }
    }
    }
    }

    应用设置后,分析器和过滤器实际上会映射到文档中,而原始 title字段完全不会受到影响!这正常吗?
    我猜这解释了为什么查询不匹配。根本没有 title.autocomplete字段或 title.title字段。

    那么我现在应该如何进行呢?

    最佳答案

    对于面临此问题的用户,最好删除索引并重新开始,而不是像_river那样浪费DrTech pointed out in the comment的时间。

    这样可以节省时间,但不是解决方案。 (因此,请勿将其标记为答案。)

    关于mongodb - ElasticSearch自动完成返回0次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21367161/

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