Skip to content

Instantly share code, notes, and snippets.

@jkdeveyra
Created May 22, 2012 05:28
Show Gist options
  • Save jkdeveyra/2766825 to your computer and use it in GitHub Desktop.
Save jkdeveyra/2766825 to your computer and use it in GitHub Desktop.
#Models
#equipment_specs.rb
class EquipmentSpec
include Mongoid::Document
field :specification, type: String
validates :specification, presence: true
field :price, type: BigDecimal
validates :price, presence: true
belongs_to :equipment
accepts_nested_attributes_for :equipment
validates :equipment, presence: true
delegate :category, to: :equipment
include Tire::Model::Search
include Tire::Model::Callbacks
def to_indexed_json
self.as_json
end
end
#equipment.rb
class Equipment
include Mongoid::Document
field :name, type: String
validates :name, presence: true, uniqueness: true
belongs_to :category
accepts_nested_attributes_for :category
validates :category, presence: true
has_many :equipment_specs, dependent: :destroy
end
#category.rb
class Category
include Mongoid::Document
field :name, type: String
validates :name, presence: true, uniqueness: true
has_many :equipment, dependent: :destroy
end
#controller
specs = EquipmentSpec.new(specification: "Canon 1300", price: BigDecimal("35.00"))
specs.equipment = Equipment.new(name: "Printer")
specs.equipment.category = Category.new(name: "Printing Supplies")
specs.equipment.category.save
specs.equipment.save
specs.save
#ElasticSearch Console
jvm 1 | [2012-05-22 13:24:07,811][INFO ][cluster.metadata ] [Equipment Search] [equipment_specs] creating index, cause [auto(index api)], shards [5]/[1], mappings []
jvm 1 | [2012-05-22 13:24:08,555][DEBUG][action.index ] [Equipment Search] [equipment_specs][0], node[C7PFwqiIQUCcs-NviO820w], [P], s[STARTED]: Failed to execute [index {[equipment_specs][equipment_spec][4fbb22f71d41c8126a000006], source[_id=4fbb22f71d41c8126a000006&equipment_id=4fbb22f71d41c8126a000007&price=35.0&specification=Canon%201300]}]
jvm 1 | org.elasticsearch.ElasticSearchParseException: Failed to derive xcontent from (offset=0, length=104): [95, 105, 100, 61, 52, 102, 98, 98, 50, 50, 102, 55, 49, 100, 52, 49, 99, 56, 49, 50, 54, 97, 48, 48, 48, 48, 48, 54, 38, 101, 113, 117, 105, 112, 109, 101, 110, 116, 95, 105, 100, 61, 52, 102, 98, 98, 50, 50, 102, 55, 49, 100, 52, 49, 99, 56, 49, 50, 54, 97, 48, 48, 48, 48, 48, 55, 38, 112, 114, 105, 99, 101, 61, 51, 53, 46, 48, 38, 115, 112, 101, 99, 105, 102, 105, 99, 97, 116, 105, 111, 110, 61, 67, 97, 110, 111, 110, 37, 50, 48, 49, 51, 48, 48]
jvm 1 | at org.elasticsearch.common.xcontent.XContentFactory.xContent(XContentFactory.java:147)
jvm 1 | at org.elasticsearch.common.xcontent.XContentHelper.createParser(XContentHelper.java:49)
jvm 1 | at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:431)
jvm 1 | at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:417)
jvm 1 | at org.elasticsearch.index.shard.service.InternalIndexShard.prepareIndex(InternalIndexShard.java:311)
jvm 1 | at org.elasticsearch.action.index.TransportIndexAction.shardOperationOnPrimary(TransportIndexAction.java:202)
jvm 1 | at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction.performOnPrimary(TransportShardReplicationOperationAction.java:532)
jvm 1 | at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction$1.run(TransportShardReplicationOperationAction.java:430)
jvm 1 | at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
jvm 1 | at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
jvm 1 | at java.lang.Thread.run(Thread.java:722)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment