标签: searchkick

如何在我的Nitrous.io盒子上设置ElasticSearch和Searchkick?

我已将searchkick gem添加到我的GEMFILE中,并且我还使用Autoparts安装了ElasticSearch 1.0.当我尝试重新索引我的一个模型时,我仍然收到连接被拒绝的消息.我想这可能是因为我的elasticsearch服务器尚未启动.我不确定如何在Nitrous.io上启动它.下面是我正在尝试运行的命令以及我收到的错误消息...

命令

rake searchkick:reindex CLASS=Player
Run Code Online (Sandbox Code Playgroud)

结果

rake aborted!
Faraday::ConnectionFailed: Connection refused - connect(2) for "localhost" port 9200
...
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails elasticsearch nitrousio searchkick

2
推荐指数
1
解决办法
1424
查看次数

Rails Searchkick/Elasticsearch has_many和belongs_to association

我试图使用Searchkick运行搜索并返回基于多个模型.

我的书模型包含了这个

class Book < ActiveRecord::Base

  searchkick

  has_many :book_subjects
  has_many :subjects, through: :book_subjects

  belongs_to :author
  belongs_to :publisher

end
Run Code Online (Sandbox Code Playgroud)

然后我的控制器有这个

def index

 if params[:search].present?
   @books = Book.search(params[:search], operator: "or")
 else
  @books = Book.all
 end
end
Run Code Online (Sandbox Code Playgroud)

我希望搜索结果能够搜索相关模型并返回任何结果 - 所以boo主题名称,作者和发布者.

谢谢

ruby-on-rails elasticsearch searchkick

2
推荐指数
1
解决办法
3033
查看次数

如何允许用户使用带有Searchkick on Rails的弹性搜索仅搜索他们的帖子?

我希望用户只能搜索他们的帖子而不显示其他用户创建的帖子.我到底该怎么做?我使用的是Elastic SearchSearchkick宝石.

我尝试了这个,但它仍然显示来自其他用户的帖子:

发布控制器

@posts = current_user.posts.search params[:search]
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails elasticsearch ruby-on-rails-4 searchkick

1
推荐指数
1
解决办法
320
查看次数

用Searchkick on Rails做一个专门的术语"更喜欢这个查询"?

给定一个使用searchkick索引到elasticsearch的Widget模型:

searchkick word: [:title], highlight: [:title], term_vector: true
Run Code Online (Sandbox Code Playgroud)

我已将这些文件编入索引:

{ title: "work with puppies" }
{ title: "work with sharks" }
{ title: "work with kittens" }
{ title: "shoot lasers at the moon" }
Run Code Online (Sandbox Code Playgroud)

我正在尝试为新的文本做一个"更像这样"(MLT)查询:

"work with lasers"
Run Code Online (Sandbox Code Playgroud)

我的目标是让它击中最后得分最高的文档因为"激光"比"使用"更专业,这在我的文档语料库中很常见.

我试过这个:

Widget.search query: { 
  mlt: {
    like_text: "work with lasers",
    min_term_freq: 1,
    boost_terms: 5,
    analyzer: 'searchkick_search2'
  } }
Run Code Online (Sandbox Code Playgroud)

但它让我回到顶部的"工作......"文档,得分最高.

我也尝试过输入一个键/ val {stopwords:['work','with']}然后我得到0结果.

有没有办法让searchkick/elasticsearch给我回复文档,这些文档具有最高分的专业术语和仅与常见术语匹配的淡化文档?

ruby-on-rails elasticsearch searchkick

1
推荐指数
1
解决办法
501
查看次数

使用ElasticSearch的Searchkick返回"Faraday :: ConnectionFailed:execution expired"

我一直在使用带有elasticsearch的searchkick gem,在Rails 4.2.0应用程序上没有任何问题.我有一个使用searchkick的视频模型.

出于某种原因rake searchkick:reindex:all,现在却始终如一地失败:

重新索引视频...耙子中止了!法拉第:: ConnectionFailed:执行过期

我最初安装了elasticsearch via brew install elasticsearch,它返回:

警告:elasticsearch-1.3.4已经安装

我的elasticsearch安装/数据库是否可能已损坏?如果是这样,刷新它的最佳方法是什么?

根据https://www.elastic.co/guide/en/elasticsearch/reference/1.4/indices-delete-index.html我试过,curl -XDELETE 'http://localhost:9200/_all'但这不能解决错误.

当我将此代码部署到AWS时,我的Mac以及Elastic Beanstalk都会出现此问题(两者以前都正常工作).

ruby-on-rails elasticsearch searchkick

1
推荐指数
1
解决办法
3571
查看次数

Searchkick仅返回某些值,而不是全部

当使用searchkick执行搜索时,我得到所有字段的结果。我想将响应限制为仅输出某些字段,例如title

# movie.rb
class Movie < ApplicationRecord
  searchkick autocomplete: ['title']
end

# search_controller.rb
def autocomplete
  render json: Movie.search(params[:query], autocomplete: true, limit: 10, fields: [:title])
end
Run Code Online (Sandbox Code Playgroud)

我的回应还是

[{"id":1,"title":"Megamind","director":"Tom McGrath","genre":"Animation | Action | Comedy","description":"The supervillain Megamind finally defeats his nemesis, the superhero Metro Man. But without a hero, he loses all purpose and must find new meaning to his life.","length":95,"year":2010,"imdb_id":"tt1001526","imdb_rating":"7.3","created_at":"2016-04-16T19:50:24.893Z","updated_at":"2016-04-16T19:50:24.893Z"}]
Run Code Online (Sandbox Code Playgroud)

我正试图只拿回标题。通过阅读不同的问题,我认为这应该与fields我的搜索有关,但这不会改变响应。我也尝试使用_source-attribute,但没有运气。

ruby-on-rails elasticsearch searchkick

1
推荐指数
1
解决办法
652
查看次数

Searchkick Elasticsearch 抛出 400 错误

我最近更新到 High Seirra,不确定这是否意味着什么,当我尝试重新索引 Active Record 模型时,我现在收到此错误。

我尝试过的事情。我已经重新安装了 RVM、Ruby、Elasticsearch。仍然遇到同样的错误。

我团队中的其他人也进行了相同的升级,并且运行得很好。以下是我收到的错误。

Elasticsearch::Transport::Transport::Errors::BadRequest: [400] {"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"Failed to parse mapping [_default_]: Could not convert [word_start.index] to boolean"}],"type":"mapper_parsing_exception","reason":"Failed to parse mapping [_default_]: Could not convert [word_start.index] to boolean","caused_by":{"type":"illegal_argument_exception","reason":"Could not convert [word_start.index] to boolean","caused_by":{"type":"illegal_argument_exception","reason":"Failed to parse value [analyzed] as only [true] or [false] are allowed."}}},"status":400}
from /Users/rrobin244/.rvm/gems/ruby-2.3.3/gems/elasticsearch-transport-5.0.4/lib/elasticsearch/transport/transport/base.rb:202:in `__raise_transport_error'
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails elasticsearch searchkick

1
推荐指数
1
解决办法
1776
查看次数

如何为 searchkick gem 设置不同的端口?

我已经在cloud9的端口8081上运行elasticsearch。

/workspace/elasticsearch-6.1.1/bin $ ./elasticsearch -E http.port=8081
Run Code Online (Sandbox Code Playgroud)

然后我在 gemfile 中添加“searchkick”gem,然后捆绑安装

然后我在模型中添加 searchkick 作为

class Book < ActiveRecord::Base
    searchkick
end
Run Code Online (Sandbox Code Playgroud)

然后我运行命令

Book.reindex
Run Code Online (Sandbox Code Playgroud)

我收到以下错误

2.3.4 :001 > Book.reindex
Faraday::ConnectionFailed: Failed to open TCP connection to localhost:9200 (Connection refused - connect(2) for "localhost" port 9200)
        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/net/http.rb:882:in `rescue in block in connect'
        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/net/http.rb:879:in `block in connect'
        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/timeout.rb:91:in `block in timeout'
        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/timeout.rb:101:in `timeout'
        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/net/http.rb:878:in `connect'
        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/net/http.rb:863:in `do_start'
        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/net/http.rb:852:in `start'
Run Code Online (Sandbox Code Playgroud)

这是有道理的,因为它假设弹性搜索服务器在默认的 9200 上运行,但我在 8081 上运行它。我如何告诉 searchkick gem 连接到 8081 端口而不是 …

ruby-on-rails elasticsearch searchkick cloud9

1
推荐指数
1
解决办法
872
查看次数

升级后 Searchkick 无法将索引映射到模型

工作环境:

  • 轨道 4.1
  • 搜索踢2.3.2

我将在控制台中执行以下查询:

res = Searchkick.search(
        "Thom",
        index_name: [Customer.searchkick_index.name, User.searchkick_index.name],
        match: :word_start,
        fields: [:first_name, :last_name, :name],
        limit: 10,
        #load: false,
        misspellings: {below: 3}
        )
Run Code Online (Sandbox Code Playgroud)

res.hits 看起来像:

=> [
{"_index"=>"customers_production_20180830135206573", "_type"=>"customer", "_id"=>"162", "_score"=>66.72488}, 
{"_index"=>"customers_production_20180830135206573", "_type"=>"customer", "_id"=>"547", "_score"=>63.447693}, 
{"_index"=>"users_production_20170616114857320", "_type"=>"user", "_id"=>"447", "_score"=>59.895348}, 
{"_index"=>"users_production_20170616114857320", "_type"=>"user", "_id"=>"412", "_score"=>58.541008}, 
{"_index"=>"users_production_20170616114857320", "_type"=>"user", "_id"=>"338", "_score"=>57.721336}, 
{"_index"=>"users_production_20170616114857320", "_type"=>"user", "_id"=>"271", "_score"=>42.91793}, 
{"_index"=>"users_production_20170616114857320", "_type"=>"user", "_id"=>"315", "_score"=>42.91793}, 
{"_index"=>"users_production_20170616114857320", "_type"=>"user", "_id"=>"201", "_score"=>42.91793}
]
Run Code Online (Sandbox Code Playgroud)

一切都按预期进行。我在搜索框中输入我的术语并得到结果。

res.first
 => #<Customer id: 162, field: yada-yada>
Run Code Online (Sandbox Code Playgroud)

升级后为:

  • 轨道 5.2
  • 搜索踢4.4.1

我做了同样的查询,我得到以下回击

资源点击数:

[
{"_index"=>"customers_staging_20200920170910290", "_type"=>"_doc", …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails elasticsearch searchkick ruby-on-rails-5

1
推荐指数
1
解决办法
850
查看次数

ruby 升级到 3.0.0 后 Searchkick 搜索方法参数错误

将 ruby​​ 版本从 2.7.2 更新到 3.0.0,默认 Searchkick 搜索行为停止工作。

错误跟踪:

ArgumentError in ProductsAvailabilitiesController#index

wrong number of arguments (given 2, expected 0..1)

searchkick (4.4.4) lib/searchkick/model.rb:43:in `searchkick_search'
...
Run Code Online (Sandbox Code Playgroud)

这是在 ruby​​ 2.7.2 上运行良好的简单搜索方法:

def search_method(query, page)
  search_options = {
    fields: [:name, :address, :comment],
    match: :word_middle,
    page: page,
    per_page: 10
  }

  search(query, search_options)
end
Run Code Online (Sandbox Code Playgroud)

这是我的 Gemfile.lock:

searchkick (4.4.4)
  activemodel (>= 5)
  elasticsearch (>= 6)
  hashie
elasticsearch (7.11.2)
  elasticsearch-api (= 7.11.2)
  elasticsearch-transport (= 7.11.2)
elasticsearch-api (7.11.2)
  multi_json
elasticsearch-transport (7.11.2)
  faraday (~> 1)
  multi_json
Run Code Online (Sandbox Code Playgroud)

有没有办法解决这个问题或者这是宝石来源中的错误?

ruby-on-rails elasticsearch searchkick ruby-3

0
推荐指数
1
解决办法
865
查看次数