我正在使用 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 上看到过几个类似的问题,但从来没有答案。
谁能解释是否可以将命名范围应用于轮胎/ Elasticsearch ?如果是这样,怎么办?
最佳答案
我不确定这是否有资格作为“答案”,但是完全被难住了,看到在 SO 上有几个关于范围和轮胎的类似未回答的问题,我建议其他有同样问题的人简单地使用另一个搜索客户端。
我的标准是它在 Heroku 上具有免费的生产层支持,相对容易实现并具有良好的文档,并支持我现有的范围。
我选择了 Swifttype,它符合所有这些标准,提供出色的 documentation , 样本 app , 和 free tier在heroku上。
关于ruby-on-rails - 如何将命名范围应用于轮胎搜索结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22152505/