【发布时间】:2015-05-07 05:24:00
【问题描述】:
我正在使用搜索 API,现在需要添加 completion suggester,我正在使用 elasticsearch-rails gem。
当我搜索文章时,一切正常 http://localhost:9200/articles/_search
"query": {
"multi_match": {
"query": "test",
"fields": [
"title", "tags", "content"
]
}
}
}
但由于我已经实现了完成建议,我必须编辑 as_indexed_json 以使其工作,但现在搜索 API 不再工作,只有建议。
这是我的文章模型:
def self.search(query)
__elasticsearch__.search(
{
query: {
multi_match: {
query: query,
fields: ['title', 'content', 'tags']
}
}
})
end
def self.suggest(query)
Article.__elasticsearch__.client.suggest(:index => Article.index_name, :body => {
:suggestions => {
:text => query,
:completion => {
:field => 'suggest'
}
}
})
end
def as_indexed_json(options={})
{
:name => self.title,
:suggest => {
:input => self.title,
:output => self.title,
:payload => {
:content => self.content,
:tags => self.tags,
:title => self.title
}
}
}.as_json
end
是否可以让 _search 和 _suggest 与同一个模型一起工作?
【问题讨论】:
-
那么,您的映射看起来如何?
标签: ruby-on-rails autocomplete elasticsearch