Searchkick - search for the same field multiple times

I use searchkick for elasticsearch integration in Rails. Below is a piece of code used for conditions, but it does not work after adding the conditions[:and] attribute, so obviously the structure of the 'and' is not correct.

All conditions:

def conditions   conditions = {}   conditions[:active] = true   conditions[:category_ids] = category_id if category_id.present?   conditions[:supplier_id] = supplier_id if supplier_id.present?   conditions[:manufacturer_id] = manufacturers.pluck(:id) if manufacturers.count > 0   conditions[:size_ids] = sizes.pluck(:id) if sizes.count > 0   conditions[:color_ids] = colors.pluck(:id) if colors.count > 0   conditions[:price_vat] = min_price..max_price   and_array = []   properties.active.each do |property|       values = []       property_options.pluck(:id).uniq.each do |option|           values << option if property.property_options.active.pluck(:id).include?(option)       end       and_array << {:'property_options.id' => values} if values.count > 0   end   conditions[:and] = and_array   conditions end 

Search query:

products = Product.includes(:image, :translations).search(     query,      where: conditions,     page: page,      per_page: per_page,      order: [{       "#{order_column}" => "#{direction}"     }],     limit: per_page,     minimum_should_match: '75%',     misspellings: {distance: 2},      fields: fields,     aggs: ['property_options.property_id', 'property_options.id', 'property_options.value_cs', 'property_options.value_en', 'size_ids', 'color_ids', 'manufacturer_id']     ) 

The goal is to search for different values within the same field (array of values) with AND operator. Something like this:

:and => [{:'property_options.id' => [1,2,3]},{:'property_options.id' => [4,5]},{:'property_options.id' => [10]}] 


Issue:

nested: QueryParsingException[[products_v1_20160726205441545] [_na] filter malformed, must start with start_object]; }]","status":400} 

I cannot figure out what's wrong with that and how to achieve that goal.

Any helps on this, really appreciated. Thank you, Miro

Replay

Category: ruby on rails Time: 2016-07-28 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.181 (s). 12 q(s)