Rails Elasticsearch-model model mapping - raw and not_analyzed

1.2k Views Asked by At

I am using the Elasticsearch-rails gem in my application. I need my index mapping in the model to look like the JSON you see below (shortened only to include only relevant pieces). The part I don't understand relates to "name." How would that mapping be setup if this is what I need it to look like?

JSON Mapping I want to Rails model to output

{  
   "recipes":{  
      "mappings":{  
         "list":{  
            "dynamic":"false",
            "properties":{  
               "creator_name":{  
                  "type":"string"
               },
               "name":{  
                  "type":"string",
                  "fields":{  
                     "raw":{  
                        "type":"string",
                        "index":"not_analyzed"
                     }
                  }
               },
               "permalink":{  
                  "type":"string"
               },
               "user_id":{  
                  "type":"string"
               }
            }
         }
      }
   }
}

Current Rails model mapping

  settings :index => { :number_of_shards => 1  } do
    mapping :dynamic => 'false' do
      indexes :user_id, :type => 'string'
      indexes :permalink, :type => 'string'
      indexes :creator_name, :type => 'string'
      indexes :name, :type => 'string' # How do i make this match the json?
    end
  end

How do I set indexing for 'name' in the model to look like the JSON?

Thanks a lot!

0

There are 0 best solutions below