Module: ElasticRecord::Index::Mapping

Included in:
ElasticRecord::Index
Defined in:
lib/elastic_record/index/mapping.rb

Instance Method Summary collapse

Instance Method Details

#delete_mapping(index_name = alias_name) ⇒ Object



16
17
18
# File 'lib/elastic_record/index/mapping.rb', line 16

def delete_mapping(index_name = alias_name)
  connection.json_delete "/#{index_name}/#{type}"
end

#get_mapping(index_name = alias_name) ⇒ Object



12
13
14
# File 'lib/elastic_record/index/mapping.rb', line 12

def get_mapping(index_name = alias_name)
  connection.json_get "/#{index_name}/#{type}/_mapping"
end

#mappingObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/elastic_record/index/mapping.rb', line 20

def mapping
  @mapping ||= {
    _source: {
      enabled: false
    },
    properties: {
      created_at: {type: "date", index: "not_analyzed", format: "dateOptionalTime"},
      updated_at: {type: "date", index: "not_analyzed", format: "dateOptionalTime"}
    },
    dynamic_templates: [
      {
        no_string_analyzing: {
          match: "*",
          match_mapping_type: "string",
          mapping: {
            type: "string",
            index: "not_analyzed"
          }
        }
      }
    ]
  }
end

#mapping=(mapping) ⇒ Object



4
5
6
# File 'lib/elastic_record/index/mapping.rb', line 4

def mapping=(mapping)
  mapping.deep_merge!(mapping)
end

#update_mapping(index_name = alias_name) ⇒ Object



8
9
10
# File 'lib/elastic_record/index/mapping.rb', line 8

def update_mapping(index_name = alias_name)
  connection.json_put "/#{index_name}/#{type}/_mapping", type => mapping
end