Skip to content

Commit 4d056ed

Browse files
committed
[MODEL] Use default doc type: _doc (#814)
1 parent 433c0f0 commit 4d056ed

File tree

7 files changed

+15
-9
lines changed

7 files changed

+15
-9
lines changed

elasticsearch-model/lib/elasticsearch/model/naming.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ module Model
55
#
66
module Naming
77

8+
DEFAULT_DOC_TYPE= '_doc'.freeze
9+
810
module ClassMethods
911

1012
# Get or set the name of the index
@@ -90,7 +92,7 @@ def default_index_name
9092
end
9193

9294
def default_document_type
93-
self.model_name.element
95+
DEFAULT_DOC_TYPE
9496
end
9597

9698
end

elasticsearch-model/test/integration/active_record_basic_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class ::Article < ActiveRecord::Base
1616
include Elasticsearch::Model
1717
include Elasticsearch::Model::Callbacks
1818

19+
document_type 'article'
20+
1921
settings index: { number_of_shards: 1, number_of_replicas: 0 } do
2022
mapping do
2123
indexes :title, type: 'text', analyzer: 'snowball'

elasticsearch-model/test/integration/active_record_custom_serialization_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def as_indexed_json(options={})
4141

4242
a = ArticleWithCustomSerialization.__elasticsearch__.client.get \
4343
index: 'article_with_custom_serializations',
44-
type: 'article_with_custom_serialization',
44+
type: '_doc',
4545
id: '1'
4646

4747
assert_equal( { 'title' => 'Test' }, a['_source'] )
@@ -55,7 +55,7 @@ def as_indexed_json(options={})
5555

5656
a = ArticleWithCustomSerialization.__elasticsearch__.client.get \
5757
index: 'article_with_custom_serializations',
58-
type: 'article_with_custom_serialization',
58+
type: '_doc',
5959
id: '1'
6060

6161
assert_equal( { 'title' => 'UPDATED' }, a['_source'] )

elasticsearch-model/test/integration/active_record_namespaced_model_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class Article < ActiveRecord::Base
2222
include Elasticsearch::Model
2323
include Elasticsearch::Model::Callbacks
2424

25+
document_type 'article'
26+
2527
mapping { indexes :title }
2628
end
2729
end

elasticsearch-model/test/unit/indexing_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class NotFound < Exception; end
149149
should "update and return the index mappings" do
150150
DummyIndexingModel.mappings foo: 'boo'
151151
DummyIndexingModel.mappings bar: 'bam'
152-
assert_equal( { dummy_indexing_model: { foo: "boo", bar: "bam", properties: {} } },
152+
assert_equal( { _doc: { foo: "boo", bar: "bam", properties: {} } },
153153
DummyIndexingModel.mappings.to_hash )
154154
end
155155

@@ -544,7 +544,7 @@ class ::DummyIndexingModelForRecreate
544544
indices.expects(:create).with do |payload|
545545
assert_equal 'dummy_indexing_model_for_recreates', payload[:index]
546546
assert_equal 1, payload[:body][:settings][:index][:number_of_shards]
547-
assert_equal 'keyword', payload[:body][:mappings][:dummy_indexing_model_for_recreate][:properties][:foo][:analyzer]
547+
assert_equal 'keyword', payload[:body][:mappings][:_doc][:properties][:foo][:analyzer]
548548
true
549549
end.returns({})
550550

elasticsearch-model/test/unit/naming_inheritance_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ class ::Cat < ::Animal
6969
end
7070

7171
should "return the default document_type" do
72-
assert_equal "test_base", TestBase.document_type
73-
assert_equal "test_base", TestBase.new.document_type
72+
assert_equal "_doc", TestBase.document_type
73+
assert_equal "_doc", TestBase.new.document_type
7474
end
7575

7676
should "return the explicit document_type" do

elasticsearch-model/test/unit/naming_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class DummyNamingModelInNamespace
2929
end
3030

3131
should "return the default document_type" do
32-
assert_equal 'dummy_naming_model', DummyNamingModel.document_type
33-
assert_equal 'dummy_naming_model', DummyNamingModel.new.document_type
32+
assert_equal '_doc', DummyNamingModel.document_type
33+
assert_equal '_doc', DummyNamingModel.new.document_type
3434
end
3535

3636
should "set and return the index_name" do

0 commit comments

Comments
 (0)