gpt4 book ai didi

python - elasticsearch映射没有JSON对象错误

转载 作者:行者123 更新时间:2023-12-03 00:59:00 25 4
gpt4 key购买 nike

我正在尝试使用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"}
}
}

最佳答案

afaik,该错误表示您的json数据无效。
“text”中,多数民众赞成在 left double quotation mark而不是" quotation mark包围。

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

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

关于python - elasticsearch映射没有JSON对象错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40835795/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com