首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Elasticsearch::Transport.Transport::Error on Heroku,ActiveAdmin,SearchKick和SearchBox

Elasticsearch::Transport.Transport::Error on Heroku,ActiveAdmin,SearchKick和SearchBox
EN

Stack Overflow用户
提问于 2016-02-20 09:20:53
回答 1查看 1.6K关注 0票数 0

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

Elasticsearch::Transport::Transport::Errors::NotFound中的Admin::PostsController#update 404中的“原因”:“post: document缺失”、“索引”:“post”、“shard”:“0”}、"type":"document_missing_exception“、”document_missing_exception“、”document_missing_exception“:”post: document缺失“、”index“:”post“、"shard":"0"},“地位”:404}

尽管它正在抛出此错误,但Post仍在更新或创建罚款。如果我刷新页面,它将按预期的方式解析为ActiveAdmin中的所有posts屏幕。搜索功能在前端完全可用。

在SearchBox中,ElasticSearch索引名为posts_production_20160220081603930。想不出如何让ActiveAdmin看到它。邮报模型看到它,我可以搜索,如预期的。

岗位管理员..。

代码语言:javascript
复制
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

Post模型

代码语言:javascript
复制
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邮政

代码语言:javascript
复制
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运行rake搜索:重新索引CLASS=Post

在dev中,索引会自动更新,但在prod中,我必须手动重新索引。还没有设置边框。

任何帮助都将不胜感激。

我有点疯了。

干杯

EN

回答 1

Stack Overflow用户

发布于 2016-02-21 10:42:21

解决了问题..。我曾使用Search腿创建和索引,但奇怪的是,似乎也需要使用Post.elasticsearch.create_index!创建索引。强制:真(非搜索)命令。因此,搜索框中的索引是posts和posts_production

全部投入运作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35521276

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档