gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 01:57:25 32 4
gpt4 key购买 nike

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

Elasticsearch::Transport::Transport::Errors::NotFound in Admin::PostsController#update [404] {"error":{"root_cause":[{"type":"document_missing_exception","reason":"[post][11]: document missing","index":"posts","shard":"0"}],"type":"document_missing_exception","reason":"[post][11]: document missing","index":"posts","shard":"0"},"status":404}



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

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

后 Controller ...
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=Post



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

任何帮助将不胜感激。

有点生气。

干杯

最佳答案

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

posts_production

全部完全运作。

关于ruby-on-rails - 使用ActiveAdmin,SearchKick和SearchBox在Heroku上出现Elasticsearch::Transport::Transport::Errors,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35521276/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com