0

如果我使用 searchkick 对 elasticsearch-rails 进行高级搜索,如下所示:

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[],
4

2 回答 2

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
于 2016-02-12T05:35:31.907 回答
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 假设bodyIS部分,如果存在子句query,它会将其转换为filtered查询。where

试试看...

于 2015-07-30T06:32:28.687 回答