Elasticsearch,允许多个组和条件用或分隔

时间:2017-12-21 22:08:23

标签: ruby-on-rails elasticsearch searchkick

试图弄清楚如何允许多组和条件用或分隔。

exercises = Exercise.search exercise_term(params[:term]), fields: exercise_fields, operator: 'or', where: exercise_filters, per_page: 20

...

private

def exercise_filters
  {
    or: [
      [{ public: true }],
      [{ account_id: nil, location_id: nil, profile_id: nil }],
      [{ account_id: current_user.account_id.to_s, save_to_clinic: true }],
      [{ location_id: current_user.current_profile.location_id.to_s, save_to_clinic: true }],
      [{ location_id: current_user.account.default_location.id.to_s, save_to_clinic: true }],
      [{ profile_id: current_user.current_profile.id.to_s }]
    ]
  }
end

```

  

ES查询:

{"query":{"bool":{"must":{"dis_max":{"queries":[{"match":
{"keywords.analyzed":{"query":"wrist","boost":10,"operator":"or","cutoff_frequency":0.001,"analyzer":"searchkick_search"}}},{"match":{"keywords.analyzed":{"query":"wrist","boost":10,"operator":"or","cutoff_frequency":0.001,"analyzer":"searchkick_search2"}}},{"match":{"keywords.analyzed":{"query":"wrist","boost":1,"operator":"or","analyzer":"searchkick_search","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}},{"match":{"keywords.analyzed":{"query":"wrist","boost":1,"operator":"or","analyzer":"searchkick_search2","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}},{"match":{"name.analyzed":{"query":"wrist","boost":30.0,"operator":"or","cutoff_frequency":0.001,"analyzer":"searchkick_search"}}},{"match":{"name.analyzed":{"query":"wrist","boost":30.0,"operator":"or","cutoff_frequency":0.001,"analyzer":"searchkick_search2"}}},{"match":{"name.analyzed":{"query":"wrist","boost":3.0,"operator":"or","analyzer":"searchkick_search","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}},{"match":{"name.analyzed":{"query":"wrist","boost":3.0,"operator":"or","analyzer":"searchkick_search2","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}},{"match":{"alias_name.analyzed":{"query":"wrist","boost":30.0,"operator":"or","cutoff_frequency":0.001,"analyzer":"searchkick_search"}}},{"match":{"alias_name.analyzed":{"query":"wrist","boost":30.0,"operator":"or","cutoff_frequency":0.001,"analyzer":"searchkick_search2"}}},{"match":{"alias_name.analyzed":{"query":"wrist","boost":3.0,"operator":"or","analyzer":"searchkick_search","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}},{"match":{"alias_name.analyzed":{"query":"wrist","boost":3.0,"operator":"or","analyzer":"searchkick_search2","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}},{"match":{"custom_tag.analyzed":{"query":"wrist","boost":10,"operator":"or","cutoff_frequency":0.001,"analyzer":"searchkick_search"}}},{"match":{"custom_tag.analyzed":{"query":"wrist","boost":10,"operator":"or","cutoff_frequency":0.001,"analyzer":"searchkick_search2"}}},{"match":{"custom_tag.analyzed":{"query":"wrist","boost":1,"operator":"or","analyzer":"searchkick_search","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}},{"match":{"custom_tag.analyzed":{"query":"wrist","boost":1,"operator":"or","analyzer":"searchkick_search2","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}},{"match":{"body_part.analyzed":{"query":"wrist","boost":10,"operator":"or","cutoff_frequency":0.001,"analyzer":"searchkick_search"}}},{"match":{"body_part.analyzed":{"query":"wrist","boost":10,"operator":"or","cutoff_frequency":0.001,"analyzer":"searchkick_search2"}}},{"match":{"body_part.analyzed":{"query":"wrist","boost":1,"operator":"or","analyzer":"searchkick_search","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}},{"match":{"body_part.analyzed":{"query":"wrist","boost":1,"operator":"or","analyzer":"searchkick_search2","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}},{"match":{"description.analyzed":{"query":"wrist","boost":10,"operator":"or","cutoff_frequency":0.001,"analyzer":"searchkick_search"}}},{"match":{"description.analyzed":{"query":"wrist","boost":10,"operator":"or","cutoff_frequency":0.001,"analyzer":"searchkick_search2"}}},{"match":{"description.analyzed":{"query":"wrist","boost":1,"operator":"or","analyzer":"searchkick_search","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}},{"match":{"description.analyzed":{"query":"wrist","boost":1,"operator":"or","analyzer":"searchkick_search2","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}},{"match":{"equipment_needed.analyzed":{"query":"wrist","boost":10,"operator":"or","cutoff_frequency":0.001,"analyzer":"searchkick_search"}}},{"match":{"equipment_needed.analyzed":{"query":"wrist","boost":10,"operator":"or","cutoff_frequency":0.001,"analyzer":"searchkick_search2"}}},{"match":{"equipment_needed.analyzed":{"query":"wrist","boost":1,"operator":"or","analyzer":"searchkick_search","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}},{"match":{"equipment_needed.analyzed":{"query":"wrist","boost":1,"operator":"or","analyzer":"searchkick_search2","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}},{"match":{"type_of_exercise.analyzed":{"query":"wrist","boost":10,"operator":"or","cutoff_frequency":0.001,"analyzer":"searchkick_search"}}},{"match":{"type_of_exercise.analyzed":{"query":"wrist","boost":10,"operator":"or","cutoff_frequency":0.001,"analyzer":"searchkick_search2"}}},{"match":{"type_of_exercise.analyzed":{"query":"wrist","boost":1,"operator":"or","analyzer":"searchkick_search","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}},{"match":{"type_of_exercise.analyzed":{"query":"wrist","boost":1,"operator":"or","analyzer":"searchkick_search2","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}},{"match":{"exercise_type.analyzed":{"query":"wrist","boost":10,"operator":"or","cutoff_frequency":0.001,"analyzer":"searchkick_search"}}},{"match":{"exercise_type.analyzed":{"query":"wrist","boost":10,"operator":"or","cutoff_frequency":0.001,"analyzer":"searchkick_search2"}}},{"match":{"exercise_type.analyzed":{"query":"wrist","boost":1,"operator":"or","analyzer":"searchkick_search","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}},{"match":{"exercise_type.analyzed":{"query":"wrist","boost":1,"operator":"or","analyzer":"searchkick_search2","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}}]}},"filter":[{"bool":{"should":[{"bool":{"filter":[{"term":{"public":true}}]}}]}},{"bool":{"should":[{"bool":{"filter":[{"bool":{"must_not":{"exists":{"field":"account_id"}}}},{"bool":{"must_not":{"exists":{"field":"location_id"}}}},{"bool":{"must_not":{"exists":{"field":"profile_id"}}}}]}}]}},{"bool":{"should":[{"bool":{"filter":[{"term":{"account_id":"5942d9d88ca7940b49000005"}},{"term":{"save_to_clinic":true}}]}}]}},{"bool":{"should":[{"bool":{"filter":[{"term":{"location_id":"5942d9d88ca7940b49000006"}},{"term":{"save_to_clinic":true}}]}}]}},{"bool":{"should":[{"bool":{"filter":[{"term":{"location_id":"5942d9d88ca7940b49000006"}},{"term":{"save_to_clinic":true}}]}}]}},{"bool":{"should":[{"bool":{"filter":[{"term":{"profile_id":"5942d9d88ca7940b49000003"}}]}}]}}]}},"size":20,"from":0,"timeout":"11s","_source":false}

这看起来对我而言ES query看起来应该符合我的预期。但我没有得到任何结果。我错过了什么?

0 个答案:

没有答案