-
Notifications
You must be signed in to change notification settings - Fork 3
/
create_index.py
executable file
·32 lines (28 loc) · 1.02 KB
/
create_index.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
#!/usr/bin/env python
from pyelasticsearch import ElasticSearch
from pyelasticsearch.exceptions import ElasticHttpNotFoundError
from settings import HOST, INDEX, DOCTYPE
index_settings = {
'mappings': {
DOCTYPE: {
'properties': {
'title': {'type': 'string', 'analyzer': 'mmseg', 'boost': 1.5, 'term_vector': 'with_positions_offsets'},
'url': {'type': 'string', 'index': 'not_analyzed'},
'content': {'type': 'string', 'analyzer': 'mmseg', 'boost': 0.7, 'term_vector': 'with_positions_offsets'},
'categories': {'type': 'nested',
'properties': {
'url': {'type': 'string', 'index': 'not_analyzed'},
'name': {'type': 'string', 'index': 'not_analyzed'},
}
}
}
}
}
}
es = ElasticSearch(HOST)
try:
es.delete_index(INDEX)
except ElasticHttpNotFoundError:
# No index found
pass
es.create_index(INDEX, settings=index_settings)