-
Notifications
You must be signed in to change notification settings - Fork 1
/
mapping.py
48 lines (36 loc) · 1.07 KB
/
mapping.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# ElasticMapping
# File: example/mapping.py
# Desc: example mapping file w/ commands
from elasticsearch import Elasticsearch
from elasticmapping import ElasticMapping, Nest
from elasticmapping.types import STRING, DATETIME, FLOAT, INTEGER
# A base mapping
class BaseMapping(ElasticMapping):
__es__ = Elasticsearch()
__index__ = 'mapping_test'
# Override all string attributes
__STRING__ = {
'index': 'not_analyzed'
}
# Example fields
slug = STRING
datetime = DATETIME({
'format': 'date_hour_minute_second_fraction'
})
# An mapping which forms an ES doc_type
class DocMapping(BaseMapping):
__doc_type__ = 'doc_mapping'
# Overrides the BaseMapping __STRING__ override
name = STRING({
'index': 'analyzed'
})
# Nested documents
nested_document = Nest(
float_type=FLOAT,
interger_type=INTEGER
)
if __name__ == '__main__':
# Print out JSON ready for ES
print 'JSON', DocMapping.json(indent=4)
# Create the mappings with provided __es__ client
print 'PUT', DocMapping.put()