我无法弄清楚如何在嵌套对象和排序上使用过滤器运行搜索查询。我一直在
[400] {"error":"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed;
我的可搜索问题看起来像这样:
module Searchable
extend ActiveSupport::Concern
included do
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
def self.search(query="", options={})
params = {
query: {
filtered: {
query: {
multi_match: {
query: query,
fields: ['title', 'description', 'product_url']
},
match_all: {}
},
filter: {
bool: {
must: [
{
terms: {
gender: options[:gender]
}
},
{
nested: {
path: 'prices',
filter: {
bool: {
must: [
{
term: { 'prices.currency' => options[:p_curr] }
}
]
}
}
}
}
]
}
}
}
},
sort: [
{
options[:order_col].try(:downcase) => {
order: 'desc'
}
}
]
}
params[:query][:filtered][:query].delete(:match_all) if query.present?
params[:query][:filtered][:query].delete(:multi_match) if query.blank?
params.delete(:sort) if options[:order_col].blank?
__elasticsearch__.search(params).page(options[:page]).per(options[:per_page])
end
# elastic search index
# ---------------------------------------------------------------------------
def as_indexed_json(options={})
as_json(
:only => [:title, :description, :product_url, :gender],
:include => [
:brand => {
:only => [:name, :slug]
},
:retailer => {
:only => [:name]
},
:product_text_tags => {
:only => [:name]
},
:prices => {
:only => [
:price_in_cents,
:currency,
:is_on_sale,
:out_of_stock,
:on_sale_price_in_cents,
:is_last_price
]
}
]
)
end
# ---------------------------------------------------------------------------
end
end
我错过了什么吗?有人可以帮忙吗?我觉得很丢失。一切都工作得很好弹性,当我删除所有条件和过滤器,它只使用普通查询时工作正常 在Rails 3上工作