【问题标题】:elasticsearch mapping no JSON object errorelasticsearch映射没有JSON对象错误
【发布时间】:2017-04-11 16:09:22
【问题描述】:

我正在尝试使用 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 映射的指南,我使用 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"}
    }
}

【问题讨论】:

    标签: python json python-2.7 elasticsearch


    【解决方案1】:

    afaik,该错误意味着您的 json 数据无效。 在“text” 中,被 left double quotation mark 包围而不是" quotation mark

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

    看到这个:Displaying better error message than "No JSON object could be decoded"

    【讨论】:

      猜你喜欢
      • 2014-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-15
      • 2012-11-20
      • 2018-03-30
      • 1970-01-01
      • 2019-05-27
      相关资源
      最近更新 更多