2016-11-28 162 views
0

我想使用python腳本csv2es將數據加載到elasticsearch 5。elasticsearch映射沒有JSON對象錯誤

傳遞給csv2es的參數通過elasticsearch映射引用一個json文件。裝載時的映射文件如下:

{ 
"dynamic": "true", 
"properties": { 
    "username": {"type": 「text」}, 
    "date": {"type": "date", "format" : "yyyy-MM-dd HH:mm"}, 
    "retweets": {"type": 「integer」}, 
    "favourites": {"type": 「integer」}, 
    "text": {"type": 「text」}, 
    "geo": {"type": 「keyword」}, 
    "mentions": {"type": 「text」}, 
    "hashtags": {"type": 「text」}, 
    "id": {"type": 「keyword」}, 
    "permalink": {"type": 「keyword」} 
    } 
} 

,這將引發以下錯誤:

Applying mapping from: csv2es_mappings.json 
Traceback (most recent call last): 
    File "/usr/local/bin/csv2es", line 11, in <module> 
    sys.exit(cli()) 
    File "/usr/local/lib/python2.7/site-packages/click/core.py", line 664, in  __call__ 
return self.main(*args, **kwargs) 
File "/usr/local/lib/python2.7/site-packages/click/core.py", line 644, in main 
rv = self.invoke(ctx) 
File "/usr/local/lib/python2.7/site-packages/click/core.py", line 837, in  invoke 
return ctx.invoke(self.callback, **ctx.params) 
File "/usr/local/lib/python2.7/site-packages/click/core.py", line 464, in invoke 
return callback(*args, **kwargs) 
File "/usr/local/lib/python2.7/site-packages/csv2es.py", line 206, in cli 
mapping = json.loads(f.read()) 
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 339, in loads 
return _default_decoder.decode(s) 
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 364, in decode 
obj, end = self.raw_decode(s, idx=_w(s, 0).end()) 
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 382, in raw_decode 
raise ValueError("No JSON object could be decoded") 
ValueError: No JSON object could be decoded 

然而,當我打開以下文件中的數據加載運行。根據ES5映射的指導,我使用textkeyword而不是string-使用string時,字段未被正確拾取和索引。

{ 
"dynamic": "true", 
"properties": { 
    "username": {"type": "string"}, 
    "date": {"type": "date", "format" : "yyyy-MM-dd HH:mm"}, 
    "retweets": {"type": "string"}, 
    "favourites": {"type": "string"}, 
    "text": {"type": "string"}, 
    "geo": {"type": "string"}, 
    "mentions": {"type": "string"}, 
    "hashtags": {"type": "string"}, 
    "id": {"type": "string"}, 
    "permalink": {"type": "string"} 
    } 
} 

回答