-
Notifications
You must be signed in to change notification settings - Fork 0
/
es_create_index.py
54 lines (51 loc) · 1.41 KB
/
es_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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from elasticsearch import Elasticsearch
from requests_aws4auth import AWS4Auth
import elasticsearch
#This python script is to create an index in elastic search with mappings specifying the type of each field
# create instance of elasticsearch
host = 'ElasticSearch_Host' #Creata a domain on ElasticSearch Service and add the endpoint here
awsauth = AWS4Auth('AWS_Access_Key', 'AWS_Access_Secret_Key', 'AWS_Region', 'es')
es = elasticsearch.Elasticsearch(
hosts=[{'host': host, 'port': 443}],
http_auth=awsauth,
use_ssl=True,
verify_certs=True,
connection_class=elasticsearch.connection.RequestsHttpConnection
)
mappings = {
"settings": {
"number_of_shards": 1,
},
"mappings": {
"tweets": {
"properties": {
"author" : {
"type" : "string",
},
"date" : {
"type" : "text",
},
"location" : {
"properties" : {
"coords" : {
"type" : "geo_point",
},
"name" : {
"type" : "text",
}
}
},
"message" : {
"type" : "text",
},
"language" : {
"type" : "text",
},
"sentiment" : {
"type" : "text"
}
}
}
}
}
es.indices.create(index='tweetmap', body=mappings)