1

私は国のリストを持っており、ユーザーが結果を国別にソートできるようにしたいと考えています。だから私はこのヘルパーを持っています:

def facets_for model, field
ul = ""
links = ""
model.facets[field]['terms'].each do |facet|
  links << content_tag('li') do
    link_to("#{facet['term']} #{facet['count']}", params.merge(field => facet['term']))
  end
end
ul << content_tag("ul", class: field) do
  links.html_safe
end
ul.html_safe

終わり

そしてモデルでは:

class model
 ....
mapping do 
 indexes :country do
   indexes :name, :type => :string, index: "not_analyzed"
 end
end




def self.search params
  ...
  filter :term, destination: params[:destination] if params[:destination].present?
  facet("destination") {  terms 'country.name' }
  ...
end

しかし

ファセット['期間']

国名を常に小文字で返します。Country.find(facet).name で作れますが、不要だと思います。フィールドと同じ文字列値をファセットに格納する方法はありますか?

更新しました

私のマッピング:

  {
      "wishes" : {
        "wish" : {
          "properties" : {
            "body" : {
              "type" : "string"
            },
            "country" : {
              "properties" : {
                "name" : {
                  "type" : "string"
                }
              }
            },
            "country_id" : {
              "type" : "string"
            },
            "created_at" : {
              "type" : "date",
              "format" : "dateOptionalTime"

      }
    } ... }}}
4

1 に答える 1

0

マッピングが正しく作成されていません。データの再インデックスを試みることができます。

Model.index.delete               # to delete index with bad mapping
Model.create_elasticsearch_index # this should create index with mapping defined in Model

その後、Model.importもう一度実行を試みることができます。

于 2013-10-22T13:48:04.800 に答える