From c3ddb8a25db3b64e5963aad3f68ba50a727f60a9 Mon Sep 17 00:00:00 2001 From: Ashwin Rao Date: Mon, 30 May 2016 12:01:06 -0600 Subject: [PATCH] Support Elasticsearch date types in import This commit modifies the DataMagic module to support the Elasticsearch "date" datatype (https://www.elastic.co/guide/en/elasticsearch/reference/current/date.html). This commit responds directly to the open issue #105 (support date type). It does not incorporate any of the work done in the issue closed as #128 ([WIP] Add date type to map_field_types method -- not tested). --- lib/data_magic.rb | 1 + spec/lib/data_magic_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/lib/data_magic.rb b/lib/data_magic.rb index 1000d5cf..aa779e8b 100644 --- a/lib/data_magic.rb +++ b/lib/data_magic.rb @@ -227,6 +227,7 @@ def self.base_index_hash(es_index_name, es_types) # convert the types from data.yaml to Elasticsearch-specific types def self.es_field_types(field_types) custom_type = { + 'date' => {type: 'date', format: "yyyy-MM-dd"}, 'literal' => {type: 'string', index:'not_analyzed'}, 'name' => {type: 'string', index:'not_analyzed'}, 'lowercase_name' => {type: 'string', index:'not_analyzed', store: false}, diff --git a/spec/lib/data_magic_spec.rb b/spec/lib/data_magic_spec.rb index ecce7d89..0d1dfc59 100644 --- a/spec/lib/data_magic_spec.rb +++ b/spec/lib/data_magic_spec.rb @@ -24,6 +24,13 @@ end end + context 'with type "date"' do + it 'returns the date field with date type in default format' do + expect(described_class.es_field_types({ 'date' => 'date' })) + .to eq({"date"=>{:type=>"date",:format=>"yyyy-MM-dd"}}) + end + end + end end