当前位置:  开发笔记 > 编程语言 > 正文

由于"404 Not Found"错误,sunspot_rails无法索引

如何解决《由于"404NotFound"错误,sunspot_rails无法索引》经验,为你挑选了0个好方法。

我正在尝试在一个小的Rails应用程序中安装Sunspot,完全遵循gem设置说明,但每当RSolr::Error::Http: RSolr::Error::Http - 404 Not Found我尝试索引数据时遇到错误.我可以用一个新的应用程序重现这个; 以下是我遵循的确切步骤:

创建一个新的Rails 4.2.5应用程序:

$ rails new test_sunspot
$ cd test_sunspot/
$ spring stop # spring can cause `generate` commands to hang
$ rails g model Thing title:string
$ rake db:migrate
$ rails c
  > Thing.create!(title: "Cats")
  > Thing.create!(title: "Pizza")
  > exit

向模型添加太阳黑子索引:

class Thing < ActiveRecord::Base
  searchable do
    text :title
  end
end

将Sunspot添加到Gemfile:

...
gem 'sunspot_rails', '2.2.2'
gem 'sunspot_solr',  '2.2.2'  
...

安装,启动和重新编制太阳黑子:

$ bundle install
$ rails g sunspot_rails:install # default sunspot.yml is not changed
$ ps aux | grep solr # confirm that no Solr services are running
$ bundle exec rake sunspot:solr:start # generates solr/ dir; no errors
$ bundle exec rake sunspot:solr:reindex

此reindex命令产生以下输出.当我进入Rails控制台并尝试创建一个新的Thing对象时,它会触发相同的错误(因为Sunspot尝试更新索引):

Skipping progress bar: for progress reporting, add gem 'progress_bar' to your Gemfile
rake aborted!
RSolr::Error::Http: RSolr::Error::Http - 404 Not Found
Error:     Not Found

URI: http://localhost:8982/solr/development/update?wt=ruby
Request Headers: {"Content-Type"=>"text/xml"}
Request Data: "type:Thing"

Backtrace: /Users/topher/.rvm/gems/ruby-2.2.0/gems/rsolr-1.0.13/lib/rsolr/client.rb:284:in `adapt_response'
/Users/topher/.rvm/gems/ruby-2.2.0/gems/rsolr-1.0.13/lib/rsolr/client.rb:190:in `execute'
/Users/topher/.rvm/gems/ruby-2.2.0/gems/rsolr-1.0.13/lib/rsolr/client.rb:176:in `send_and_receive'
# ...lots of backtrace omitted...
/Users/topher/.rvm/gems/ruby-2.2.0/gems/sunspot_rails-2.2.2/lib/sunspot/rails/tasks.rb:19:in `block (2 levels) in '
/Users/topher/.rvm/gems/ruby-2.2.0/bin/ruby_executable_hooks:15:in `eval'
/Users/topher/.rvm/gems/ruby-2.2.0/bin/ruby_executable_hooks:15:in `
' Tasks: TOP => sunspot:solr:reindex => sunspot:reindex (See full trace by running task with --trace)

ps aux | grep solr(在启动Solr之后)的输出:注意,提到的PID solr/pids/development/sunspot-solr-development.pid62449,它匹配第三行:

topher          62617   0.0  0.0  2432772    520 s002  R+    3:00PM   0:00.00 grep solr
topher          62484   0.0  1.3  3274624 105756   ??  S     2:57PM   0:03.65 /usr/bin/java -server -Xss256k -Xms512m -Xmx512m -XX:NewRatio=3 -XX:SurvivorRatio=4 -XX:TargetSurvivorRatio=90 -XX:MaxTenuringThreshold=8 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:ConcGCThreads=4 -XX:ParallelGCThreads=4 -XX:+CMSScavengeBeforeRemark -XX:PretenureSizeThreshold=64m -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=50 -XX:CMSMaxAbortablePrecleanTime=6000 -XX:+CMSParallelRemarkEnabled -XX:+ParallelRefProcEnabled -verbose:gc -XX:+PrintHeapAtGC -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime -Xloggc:/Users/topher/.rvm/gems/ruby-2.2.0/gems/sunspot_solr-2.2.2/solr/server/logs/solr_gc.log -DSTOP.PORT=7982 -DSTOP.KEY=solrrocks -Djetty.port=8982 -Dsolr.solr.home=/Users/topher/Sites/john_kole/test_sunspot/solr -Dsolr.install.dir=/Users/topher/.rvm/gems/ruby-2.2.0/gems/sunspot_solr-2.2.2/solr -Duser.timezone=UTC -Djava.net.preferIPv4Stack=true -jar start.jar
topher          62449   0.0  0.0  2444632   1304   ??  Ss    2:57PM   0:00.04 bash ./solr start -f -p 8982 -s /Users/topher/Sites/john_kole/test_sunspot/solr

其他详情:

我在Mac OSX优胜美地

我已经卸载并重新安装了相关的宝石,尝试降级到Sunspot 1.3.0,甚至跑了gem pristine --all,结果没有变化

编辑:我阅读太阳黑子/ Solr 404 Not Found错误的其他类似门票.看起来这些情况下的解决方案相当于"重置"Solr配置并且与新的(开发环境)项目无关:在运行rake sunspot之前没有先前的Solr实例正在运行:solr:start; 这是一个完全新鲜的Rails项目,所以solr /目录只是新生成的; 这是在发展,而不是生产; 并加入solr_home: solrsunspot.yml或更新path: /solr/default对404结果没有影响.

问题:

知道为什么会这样吗?

这种破坏可能是由于我的OSX环境中安装错误造成的吗?我该怎么看?

您是否可以按照相同的步骤在新安装的当前Rails上使Sunspot正常工作?

提前致谢!

推荐阅读
地之南_816
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有