【问题标题】:How can you apply a named scope to Tire search results?如何将命名范围应用于轮胎搜索结果?
【发布时间】:2014-03-03 16:52:47
【问题描述】:

我正在使用 Tire gem 将 Elasticsearch 集成到我的应用程序中,但是当我尝试将我的命名范围应用于它时它会引发错误:

scope :unflagged, -> { where('flags_count < 4') }


def self.search(params)
  tire.search(page: params[:page], per_page: 12) do
        query { string params[:query], default_operator: "AND" } if params[:query].present?   
    sort { by :unflagged } if params[:query].blank?
     end
end

错误:

400 : {"error":"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[JDdrV2g5RWiePD6SezSHvQ][posts][1]: SearchParseException[[posts][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"sort\":[\"unflagged\"],\"size\":12}]]]; nested: SearchParseException[[posts][1]: from[-1],size[-1]: Parse Failure [No mapping found for [unflagged] in order to sort on]]; }{[JDdrV2g5RWiePD6SezSHvQ][posts][2]: SearchParseException[[posts][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"sort\":[\"unflagged\"],\"size\":12}]]]; nested: SearchParseException[[posts][2]: from[-1],size[-1]: Parse Failure [No mapping found for [unflagged] in order to sort on]]; }{[JDdrV2g5RWiePD6SezSHvQ][posts][0]: SearchParseException[[posts][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"sort\":[\"unflagged\"],\"size\":12}]]]; nested: SearchParseException[[posts][0]: from[-1],size[-1]: Parse Failure [No mapping found for [unflagged] in order to sort on]]; }{[JDdrV2g5RWiePD6SezSHvQ][posts][4]: SearchParseException[[posts][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"sort\":[\"unflagged\"],\"size\":12}]]]; nested: SearchParseException[[posts][4]: from[-1],size[-1]: Parse Failure [No mapping found for [unflagged] in order to sort on]]; }{[JDdrV2g5RWiePD6SezSHvQ][posts][3]: SearchParseException[[posts][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"sort\":[\"unflagged\"],\"size\":12}]]]; nested: SearchParseException[[posts][3]: from[-1],size[-1]: Parse Failure [No mapping found for [unflagged] in order to sort on]]; }]","status":400}

我在 SO 上看到过一些类似的问题,但从来没有答案。

谁能解释是否可以将命名范围应用于轮胎/弹性搜索?如果有,怎么做?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 scope elasticsearch tire


    【解决方案1】:

    我不确定这是否符合“答案”的要求,但是完全被难住了,看到在 SO 上有几个关于范围和轮胎的类似未回答的问题,我建议其他有相同问题的人只需使用另一个搜索客户端.

    我的标准是它在 Heroku 上提供免费的生产层级支持,相对容易实施并具有良好的文档,并支持我现有的范围。

    我选择了符合所有这些标准的 Swiftype,在 heroku 上提供了出色的 documentation、示例 appfree tier

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-18
      • 2012-04-14
      相关资源
      最近更新 更多