我正在使用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上发布了几个类似的问题,但从来没有回答。
有人可以解释是否可以将命名范围应用于Tire / Elasticsearch?如果是这样,怎么样?
答案 0 :(得分:0)
我不确定这是否有资格作为'答案',但是完全难以接受并且看到有关于范围和Tire on SO的几个类似未解答的问题,我会建议其他任何有同样问题的人使用其他搜索客户端
我的标准是它在Heroku上有免费的层生产支持,使用良好的文档相对容易实现,并支持我现有的范围。
我已使用符合所有这些条件的Swiftype,在heroku上提供了优秀的documentation,示例app和free tier。