Elastic Search Python mappings

Hi,

I've written some python code to read a csv and create an index

#!/usr/local/bin/python

import sys
import os
import csv
import codecs
from elasticsearch import Elasticsearch

csvfile="fintech_investments.csv"

#create the index mapping

mapping = {
"fintech-map": {
"properties": {
"Year": {"type": "integer"},
"Country": {"type": "keyword", "index": "not_analyzed", "analyzer": "snowball"},
"Company": {"type": "keyword", "index": "not_analyzed", "analyzer": "snowball"},
"Category": {"type": "keyword","index": "not_analyzed"},
"Investment Amount Received": {"type": "float","index": "not_analyzed"},
"Description": {"type": "keyword", "index": "not_analyzed"}
}
}
}

es = Elasticsearch(['10.132.32.75'])
if not es.indices.exists("fintech-investments"):
es.indices.create("fintech-investments")

es.indices.put_mapping(index="fintech-investments",doc_type="fintech-map",body=mapping)

with open(csvfile,'rb') as csvdata:
reader=csv.reader(csvdata,delimiter=",",quotechar='"')
reader.next()
for id, row in enumerate(reader):
print row
content = {
"Year":row[0],
"Country":row[1],
"Company":row[2],
"Category":row[3],
"Investment Amount Received":row[4],
"Description":row[5]
}
es.index(index="fintech-investments",doc_type="fintech-map",id=id,body=content)

whilst, this works, i would like to change the analyser type where in the code do i define the analyser type ?

Please use code formatting, otherwise it makes things very hard to read.

You already have that, it's at the end of this line;

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.