繁体   English   中英

使用ActiveAdmin,SearchKick和SearchBox在Heroku上出现Elasticsearch :: Transport :: Transport :: Errors

[英]Elasticsearch::Transport::Transport::Errors on Heroku with ActiveAdmin, SearchKick and SearchBox

我有一个带有Post模型和控制器的Rails应用程序,并且正在使用ActiveAdmin for CMS。 我已经实现了ElasticSearch和SearchKick,现在正尝试使用SearchBox部署到Heroku。 该应用程序在本地没有问题,并且大多数功能均可在Heroku上运行,但是在Active Admin中更新或创建帖子时遇到了一个非常烦人的错误。

Elasticsearch :: Transport :: Transport :: Errors :: NotFound在Admin :: PostsController#update [404] {“错误”:{“ root_cause”:[{“类型”:“ document_missing_exception”,“原因”:“ [ ] [11]:文档丢失”,“索引”:“帖子”,“碎片”:“ 0”}],“类型”:“ document_missing_exception”,“原因”:“ [post] [11]:文档丢失” “索引”: “岗位”, “碎片”: “0”}, “状态”:404}

即使引发此错误,帖子仍然可以更新或创建。 如果刷新页面,它将按预期解析为ActiveAdmin中的“查看所有帖子”屏幕。 搜索功能在前端完全可用。

在SearchBox中,ElasticSearch索引的名称为posts_production_20160220081603930。 无法解决如何使ActiveAdmin看到它的问题。 邮政模型看到了,我能够按预期进行搜索。

后控制器...

class PostsController < ApplicationController
  before_filter :find_post, :only => [:show, :edit, :update, :destroy]

  def index
    @post = Post.all
    if params[:q].present?
      @postsearch = Post.search params[:q], fields: [:title, :body], operator: "or", suggest: true
    end
  end

  def show
    if params[:q].present?
      @postsearch = Post.search params[:q], fields: [:title, :body], operator: "or", suggest: true
    else
      @post = Post.find(params[:id])
      respond_to do |format|
        format.html # show.html.erb
        format.xml  { render :xml => @post }
      end
    end
  end

  def create
    @post = Post.new(params[:post])
    respond_to do |format|
      if @post.save
        format.html  { redirect_to(@post, :notice => 'Post was successfully created.') }
        format.json  { render :json => @post, :status => :created, :location => @post }
      else
        format.html  { render :action => "new" }
        format.json  { render :json => @post.errors, :status => :unprocessable_entity }
      end
    end
  end

  def new
    @post = Post.new
    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @post }
    end
  end

  def edit
    @post = Post.find(params[:id])
  end

  def update
    @post = Post.find(params[:id])
    respond_to do |format|
      if @post.update_attributes(params[:post])
        flash[:notice] = 'Post was successfully updated.'
        format.html { redirect_to(@post) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @post.errors,
                    :status => :unprocessable_entity }
      end
    end
  end

  def destroy
    @post = Post.find(params[:id])
    @post.destroy
    respond_to do |format|
      format.html { redirect_to(posts_url) }
      format.xml  { head :ok }
    end
  end

  private

  def find_post
    @post = Post.find(params[:id])
  end
end

邮政模型

require 'elasticsearch/model'
class Post < ActiveRecord::Base
  searchkick suggest: [:title]
  #add attachement declaration to moidels for refile image uploading
  include Elasticsearch::Model
  include Elasticsearch::Model::Callbacks
  validates_presence_of :title, :body
  attachment :profile_image
  attachment :image
end

ActiveAdmin帖子

ActiveAdmin.register Post do
  # See permitted parameters documentation:
  # https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
  permit_params :title, :body, :profile_image, :image

  form do |f|
    inputs 'Details' do
      input :title
      input :body, :input_html => {:class => "redactor"}
      input :profile_image, :required => false, :as => :file, destroy: false, :direct => true
      input :image, :required => false, :as => :file, destroy: false, :direct => true
      actions
    end
  end
end

创建我运行的原始索引

heroku run rake searchkick:reindex CLASS =发布

在dev中,索引会自动更新,但在prod中,我必须手动重新索引。 尚未设置sidekiq。

任何帮助将不胜感激。

有点生气。

干杯

解决的问题...我曾使用Searchkick创建和建立索引,但奇怪的是,似乎还需要使用Post创建索引。 elasticsearch .create_index! force:true,即非Searchkick命令。 因此Searchbox中的索引是posts和posts_production

全部完全运作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM