From e72541da61b36fc2644c304f1c19161fe31d9ac7 Mon Sep 17 00:00:00 2001 From: Richard Stewart Date: Wed, 11 Dec 2013 11:53:13 +0100 Subject: [PATCH] [MODEL] Updated the Mongoid example in the README to include `as_indexed_json` method Default Mongoid serialization keeps the `_id` property in the JSON as "BSON Object", which breaks Elasticsearch. See: * https://github.com/elasticsearch/elasticsearch/issues/3517 * https://github.com/rails-api/active_model_serializers/issues/354#issuecomment-26805414 --- elasticsearch-model/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/elasticsearch-model/README.md b/elasticsearch-model/README.md index 19343e4..4498253 100644 --- a/elasticsearch-model/README.md +++ b/elasticsearch-model/README.md @@ -535,6 +535,10 @@ class Article attr_accessible :id, :title, :published_at include Elasticsearch::Model + + def as_indexed_json(options={}) + as_json(except: [:id, :_id]) + end end Article.create id: '1', title: 'Quick brown fox'