Searchkick高级搜索主体子句使where子句无效

时间:2015-07-30 02:30:51

标签: ruby-on-rails elasticsearch searchkick

如果我使用searchkick进行高级搜索,请搜索如下弹性搜索:

products = Activity.search body: {query: {bool: {must: [{ range: { min_age: {lte: 5} } }, { range: { max_age: {gte: 3} } } ] } } }, where: { category: "Programs", start_time: '2015-07-22' }

...没有应用where子句。这是预期的吗?我必须使用body来实现我的所有查询吗?有没有办法在searchkick中解决这个问题?

慢速日志输出:

[2015-07-29 21:03:53,369][INFO ][index.search.slowlog.query] [ES Dev] [activities_development_20150729165655530][2] took[21.1ms], took_millis[21], types[], stats[], search_type[QUERY_THEN_FETCH], total_shards[5], source[{"query":{"bool":{"must":[{"range":{"min_age":{"lte":5}}},{"range":{"max_age":{"gte":3}}}]}}}], extra_source[],

2 个答案:

答案 0 :(得分:0)

我想你需要试试这个:

products = Activity.search body: {bool: {must: [{ range: { min_age: {lte: 5} } }, { range: { max_age: {gte: 3} } } ] } }, where: { category: "Programs", start_time: '2015-07-22' }

区别在于body在第一级不包含query字段。我认为searchkick假设bodyquery部分,如果存在filtered子句,它会将其转换为where查询。

尝试一下......

答案 1 :(得分:0)

conditions = { category: "Programs", start_time: '2015-07-22' }

query = Activity.search params[:query], execute: false, where : conditions

query.body[:query] =   {bool: {must: [{ range: { min_age: {lte: 5} } }, { range: { max_age: {gte: 3} } } ] } }

query.body[:size] = 10

query.execute