-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex_tweets.py
105 lines (100 loc) · 3.6 KB
/
index_tweets.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from elasticsearch import Elasticsearch
import constants
def init_index():
constants.ES_CLIENT.indices.create(
index = constants.INDEX_NAME,
body = {
"settings": {
"index": {
"number_of_shards": 3,
"number_of_replicas": 0
},
"analysis": {
"analyzer": {
constants.ANALYZER_NAME: {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"asciifolding",
"cust_stop",
"my_snow"
]
},
constants.ANALYZER_NAME_SHINGLE: {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"asciifolding",
"cust_stop",
"my_snow",
"shingle_filter"
]
}
},
"filter": {
"cust_stop": {
"type": "stop",
"stopwords_path": "stoplist.txt",
},
"shingle_filter" : {
"type" : "shingle",
"min_shingle_size" : 2,
"max_shingle_size" : 2,
"output_unigrams": True
},
"my_snow" : {
"type" : "snowball",
"language" : "English"
}
}
}
}
}
)
press_mapping = {
constants.TYPE_NAME: {
"dynamic": "strict",
"properties": {
"_id": {
"type": "string",
"store": True,
"index": "not_analyzed"
},
"text": {
"type": "multi_field",
"fields": {
"text": {
"include_in_all": False,
"type": "string",
"store": False,
"index": "not_analyzed"
},
"_analyzed": {
"type": "string",
"store": True,
"index": "analyzed",
"term_vector": "with_positions_offsets",
"analyzer": constants.ANALYZER_NAME
},
"_analyzed_shingles": {
"type": "string",
"store": True,
"index": "analyzed",
"term_vector": "with_positions_offsets",
"analyzer": constants.ANALYZER_NAME_SHINGLE
}
}
}
}
}
}
constants.ES_CLIENT.indices.put_mapping (
index = constants.INDEX_NAME,
doc_type = constants.TYPE_NAME,
body = press_mapping
)
print "The index has been initialised!"
if __name__ == "__main__":
init_index()