So, I'm pushing CSV Data into Elastic Search using python. I'm able to push the data and an index is getting created but the mappings of the index contain only text and keyword. Even if there is a field with the type "long", "double", or "date" it is getting created in the text field. I tried to change the mappings of the index but it is still not changing. Can anybody help me with this? Here, is the code I'm working with:
from elasticsearch import Elasticsearch, helpers
import configparser
import csv
config = configparser.ConfigParser()
config.read('D:/Pushing data/push/example.ini')
es = Elasticsearch( cloud_id=config['ELASTIC']['cloud_id'], basic_auth=(config['ELASTIC']['user'], config['ELASTIC']['password']))
print(es.info())
settings = {
"number_of_shards": 2,
"number_of_replicas": 1
}
mappings = {
"properties": {
"@timestamp": {
"type": "date"
},
"cleanText": {
"type": "text",
"fielddata": True
},
"content": {
"type": "keyword"
},
"description": {
"type": "text",
"fielddata": True
},
"followers": {
"type": "long"
},
"following": {
"type": "long"
},
"hashtags": {
"type": "keyword"
},
"id": {
"type": "long"
},
"lang": {
"type": "keyword"
},
"likeCount": {
"type": "long"
},
"mentions": {
"type": "keyword"
},
"no": {
"type": "long"
},
"retweetCount": {
"type": "long"
},
"source": {
"type": "keyword"
},
"status": {
"type": "keyword"
},
"subjectivity": {
"type": "double"
},
"time": {
"type": "date",
"format": "epoch_millis"
},
"topic": {
"type": "keyword"
},
"totaltweets": {
"type": "long"
},
"translatedText": {
"type": "text",
"fielddata": True
},
"url": {
"type": "keyword"
},
"user_location": {
"type": "keyword"
},
"user_username": {
"type": "keyword"
},
"user_verified": {
"type": "keyword"
},
"vaderSentiment": {
"type": "double"
}
}
}
with open('D:/Pushing data/push/Topic_Lionel Messi.csv','r',encoding="UTF-8") as f:
reader = csv.DictReader(f)
helpers.bulk(es,reader, index = "topic_messi")
#es.update(index = "messi2", settings = settings, mappings=mappings)