我正在使用python將文件導入ElasticSearch
。簡單的數據,我可以導入但面臨的問題時,有字母和數字的組合,以及特殊字符。ElasticSearch使用python
我使用下面的腳本:
from datetime import datetime
from elasticsearch import Elasticsearch
import os
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
f = open("E:\\ElasticSearch\\test.txt",'r')
fulldata = f.readlines()
f.close()
del fulldata[0]
for line in fulldata:
array = line.split(",")
guid = array[0]
senderid = array[1]
campaign = array[2]
json_body = "{\"guid\" : \""+ guid+"\", \"senderid\" : \""+ senderid+"\", \"campaign\" : "+ str(campaign)+"}}"
print json_body
res = es.index(index="mytest", doc_type="msg", id=guid, body=json_body)
test.txt文件包含像
guid senderid campaign
26fac319-604b-11e5-b1fe,003001,Weekday_EGV_21Sept_4pm_Round2_Tier1_Part1,
數據我收到錯誤,如
elasticsearch.exceptions.RequestError: TransportError<400, u"MapperParsingException [failed to parse ]; nested: JsonParseException [Unrecognized token 'Weekday_EGV_21Sept_4pm_Round2_Tired1_Part1' : was excepting ('true', 'false' or 'null')\n at [Source: [[email protected]; line: 1, column:95}}; ")
你可以請**發佈你的代碼而不是代碼的_picture_嗎? – tzaman
從日期時間的日期時間輸入從 進口elasticsearch Elasticsearch 進口OS ES = Elasticsearch([{ '主機': '本地主機', '端口':9200}]) F =打開(「E:\\ ElasticSearch \\ test.txt的 「 'R') fulldata = f.readlines() f.close() 德爾fulldata [0] 用於fulldata行: \t陣列= line.split(」,「) \t guid = array [0] \t senderid = array [1] \t campaign = array [2] \t \t \t json_body =「{\」guid \「:\」「+ guid +」\「,\」senderid \「:\」「+ senderid +」\「,\」campaign \「: + 「}}」 \t \t \t打印json_body \t解析度= es.index(指數= 「mytest的」,DOC_TYPE = 「味精」,ID = GUID,身體= json_body) –
請編輯成你的問題本身,而不是張貼它作爲評論。 – tzaman