elasticsearch mapping没有JSON对象错误

时间:2021-01-27 00:11:16

I'm trying to load data to elasticsearch 5 using the python script csv2es.

我正在尝试使用python脚本csv2es将数据加载到elasticsearch 5。

argument passed to csv2es references a json file with the elasticsearch mappings. when loading the mappings file below:

传递给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”}
    }
}

this throws the following error:

这会引发以下错误:

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

However when I load the following file the data load runs. I'm using text and keyword instead of string as per the guidance for ES5 mappings- when using string the fields are not picked up and indexed properly.

但是,当我加载以下文件时,数据加载运行。我根据ES5映射的指导使用文本和关键字而不是字符串 - 当使用字符串时,字段未被拾取并正确索引。

{
"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"}
    }
}

1 个解决方案

#1


2  

afaik, that error means your json data is invalid. In “text”, thats surrounded by left double quotation mark instead " quotation mark.

afaik,该错误意味着您的json数据无效。在“文本”中,用“左双引号”代替“引号”。

Upgrade your python, so you can see readable error while decode json string or use simplejson library.

升级您的python,以便在解码json字符串或使用simplejson库时可以看到可读错误。

See this: Displaying better error message than "No JSON object could be decoded"

请参阅:显示比“无法解码JSON对象”更好的错误消息

#1


2  

afaik, that error means your json data is invalid. In “text”, thats surrounded by left double quotation mark instead " quotation mark.

afaik,该错误意味着您的json数据无效。在“文本”中,用“左双引号”代替“引号”。

Upgrade your python, so you can see readable error while decode json string or use simplejson library.

升级您的python,以便在解码json字符串或使用simplejson库时可以看到可读错误。

See this: Displaying better error message than "No JSON object could be decoded"

请参阅:显示比“无法解码JSON对象”更好的错误消息