Ruby on rails Elasticsearch查询多个索引,同时限制一个索引的字段
我有一个带有results方法的Ruby on rails Elasticsearch查询多个索引,同时限制一个索引的字段,ruby-on-rails,ruby,
elasticsearch,searchkick,Ruby On Rails,Ruby,
elasticsearch,Searchkick,我有一个带有results方法的Autocomplete类,该方法查询两个不同的模型以返回数据。它部分工作很好,但有一个主要问题 def results Searchkick.search @query, index_name: [Location, DiveCenter] end 我需要限制从索引DiveCenter返回的点击次数,因为我设置索引的方式。它是这样设置的,因为用户可以单击DiveCenter并被带到DiveCenter显示页面,或者单击某个位置并被带到/sear
Autocomplete
类,该方法查询两个不同的模型以返回数据。它部分工作很好,但有一个主要问题
def results
Searchkick.search @query, index_name: [Location, DiveCenter]
end
我需要限制从索引DiveCenter
返回的点击次数,因为我设置索引的方式。它是这样设置的,因为用户可以单击DiveCenter
并被带到DiveCenter
显示页面,或者单击某个位置并被带到/search?(城市|国家)=value
searchkick searchable: [:name, :city, :state, :country]
def search_data
{
name: name,
city: location.city,
state: location.state,
country: location.country
}
end
所以基本上,我需要的是:
def results
Searchkick.search @query, index_name: [Location, DiveCenter], fields: ['location.city', 'location.state', 'location.country', 'dive_center.name']
end
Elasticsearch不提供限制单个索引结果的方法 一种方法是用Ruby过滤结果
另一种方法是限制潜水中心的结果。如何查询elasticsearch(搜索或建议)?我通过搜索进行查询