【发布时间】:2014-02-17 11:35:29
【问题描述】:
我正在尝试为我们在 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 字段。
那我现在应该怎么做呢?
【问题讨论】:
-
从您所展示的内容来看,它对我来说看起来不错,所以我认为缺少一些东西。你能更新完整的映射吗(使用 GET /title_autocomplete/title/_mapping 从 Elasticsearch 检索,加上完整的命令来索引和搜索你的文档。你可能想使用
explainAPI 告诉你为什么没有匹配。跨度> -
@DrTech:这是我为复制相同问题所采取的完整步骤:hastebin.com/wovihomaxi.vala
-
您应该如何进行?删除并重新开始:) 首先使用 curl,然后使用 mongo 解决。我建议不要使用 mongo 河。只需通过您的应用将更改推送到 ES。
标签: mongodb autocomplete elasticsearch elasticsearch-mongo-river