我正在尝试使用python脚本csv2es将数据加载到elasticsearch 5。
传递给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映射的指南使用text
和keyword
而不是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"}
}
}
答案 0 :(得分:2)
afaik,该错误意味着您的json数据无效。
在ui:repeat
中,private ICoreService mService;
private boolean mConnected = false;
private boolean mConnecting = false;
private List<Something> mPendingTasks = new ArrayList<Something>;
private void bindService() {
try {
Intent service = new Intent();
service.setClassName(Constants.THE_SERVICE_PACKAGE_NAME, Constants.THE_SERVICE_FULL_NAME);
mContext.bindService(service, mServiceConnection, Context.BIND_AUTO_CREATE);
mConnecting = true;
} catch (Exception e) {
//handle exception
}
}
public void serviceDoSomething(Something task) {
try {
if (mService == null) {
synchronized (mPendingTasks) {
mPendingTasks.add(task);
}
} else {
mService.doSomething(task);
}
} catch (Exception e) {
//handle exception
}
}
private ServiceConnection mServiceConnection = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
mConnected = false;
mConnecting = false;
mService = null;
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mConnected = true;
mConnecting = false;
mService = ICoreService.Stub.asInterface(service);
drainPendingTasks();
}
};
private void drainPendingTasks() {
new Thread(new Runnable() {
@Override
public void run() {
synchronized (mPendingTasks) {
try {
if (!mPendingTasks.isEmpty()) {
for (Something task : mPendingTasks) {
mService.doSomething(task);
}
mPendingTasks.clear();
}
} catch (Exception e) {
//handle exception
}
}
}
}).start();
}
left double quotation mark包围“text”
quotation mark。
升级你的python,这样你就可以在解码json字符串时看到可读错误或使用“
库。
请参阅:Displaying better error message than "No JSON object could be decoded"