Elasticsearch在限制一个索引的字段的同时查询多个索引

时间:2018-06-13 11:38:59

标签: ruby-on-rails ruby elasticsearch searchkick

我有一个Autocomplete类,其中包含一个查询两个不同模型以返回数据的结果方法。它部分工作得很好,但有一个主要问题。

  def results
    Searchkick.search @query, index_name: [Location, DiveCenter]
  end

我需要限制从索引DiveCenter返回的命中数,因为我设置索引的方式。它是以这种方式设置的,因为用户可以点击DiveCenter并转到DiveCenter显示页面或点击某个位置并转到/search?(city | country)=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

1 个答案:

答案 0 :(得分:0)

Elasticsearch没有提供一种方法来限制单个索引的结果。

一种方法是在Ruby中过滤结果。

另一种方法是使用multi search来限制潜水中心的结果。

相关问题