我正在使用elasticsearch-rails gem实现完成建议程序。除了更新和删除之外,一切都可以正常工作。
例如,当我更新一篇文章的标题并再次尝试研究时,相同的标题仍然存在。
我已经包含了Elasticsearch::Model::Callbacks
型号:
require 'elasticsearch/model'
class Article < ActiveRecord::Base
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
def self.suggest(query)
Article.__elasticsearch__.client.suggest(:index => Article.index_name, :body => {
:suggestions => {
:text => query,
:completion => {
:field => 'suggest'
}
}
})
end
settings :index => { :number_of_shards => 1 } do
mappings :dynamic => 'false' do
indexes :title, :type => 'string', :analyzer => 'english'
indexes :suggest, :type => 'completion', :index_analyzer => 'simple', :search_analyzer => 'simple', :payloads => true
end
end
def as_indexed_json(options={})
{
:name => self.title,
:suggest => {
:input => [self.title, self.content],
:output => self.title,
:payload => {
:id => self.id,
:content => self.content
}
}
}
end
end控制器:
class ArticlesController < ApplicationController
def update
@article = Article.find(params[:id])
if @article.update_attributes(article_params)
render :json => @article
else
render :json => @article.errors
end
end
# ...
end发布于 2015-01-28 20:24:57
我们也有同样的问题。
更改自动完成数据的唯一方法是调用optimize API。优化将导致线段合并。补全建议存储在它们自己的数据结构调用FST中。它们不是常规索引的一部分,因此仅仅刷新是行不通的。用于存储完成建议的数据结构仅在索引时创建,当新段被写入时。所有旧数据都将可用,直到完全清理发生为止,这只有在合并段时才能保证。
所以调用optimize:
http://localhost:9200/indexName/_optimize?max_num_segments=number_of_segments
http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/merge-process.html#optimize-api
段的数量越少,完成的性能就越好。
然后再检查一遍。对我来说,它起作用了!
优化很慢,I/O很重,所以你不能一直运行它,也许一天运行一次……
祝好运!
https://groups.google.com/forum/?fromgroups#!searchin/elasticsearch/completion$20suggester$20delete/elasticsearch/8Rfg4kGV0ps/YG0V9jM7JhcJ
http://www.elasticsearch.org/blog/you-complete-me/
https://stackoverflow.com/questions/27913227
复制相似问题