首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >将大量数据加载到弹性搜索中时出错

将大量数据加载到弹性搜索中时出错
EN

Stack Overflow用户
提问于 2016-07-04 01:13:49
回答 1查看 1.9K关注 0票数 0

我在python中使用Elasticsearch。我有熊猫框架中的数据(3列),然后我添加了两列_index和_type,并使用熊猫内置方法将数据转换为json和每条记录。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
data =  data.to_json(orient='records') 

这是我的数据,

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[{"op_key":99140046678,"employee_key":991400459,"Revenue Results":6625.76480192,"_index":"revenueindex","_type":"revenuetype"},     
 {"op_key":99140045489,"employee_key":9914004258,"Revenue Results":6691.05435536,"_index":"revenueindex","_type":"revenuetype"},
......
}]

我的地图是:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
user_mapping =  {
        "settings" : {
            "number_of_shards": 3,
            "number_of_replicas": 2
        },

        'mappings': {
            'revenuetype': {
                'properties': {
                    'op_key':{'type':'string'},
                    'employee_key':{'type':'string'},
                    'Revenue Results':{'type':'float','index':'not_analyzed'},
                }
            }
        }
    }

然后在使用helpers.bulk(es,data)时面临此错误:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
    Traceback (most recent call last):
      File "/Users/adaggula/Documents/workspace/ElSearchPython/sample.py", line 59, in <module>
        res = helpers.bulk(client,data)
      File "/Users/adaggula/workspace/python/pve/lib/python2.7/site-packages/elasticsearch/helpers/__init__.py", line 188, in bulk
        for ok, item in streaming_bulk(client, actions, **kwargs):
      File "/Users/adaggula/workspace/python/pve/lib/python2.7/site-packages/elasticsearch/helpers/__init__.py", line 160, in streaming_bulk
        for result in _process_bulk_chunk(client, bulk_actions, raise_on_exception, raise_on_error, **kwargs):
      File "/Users/adaggula/workspace/python/pve/lib/python2.7/site-packages/elasticsearch/helpers/__init__.py", line 89, in _process_bulk_chunk
        raise e
    elasticsearch.exceptions.RequestError: TransportError(400, u'action_request_validation_exception', u'Validation Failed: 1: index is
 missing;2: type is missing;3: index is missing;4: type is missing;5: index is 
missing;6: ....... type is missing;999: index is missing;1000: type is missing;')

看起来每个json对象都缺少索引和类型。如何克服这一问题?

EN

回答 1

Stack Overflow用户

发布于 2016-07-04 02:10:49

Pandas数据帧到json转换是解决问题的关键。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
data =  data.to_json(orient='records')
data= json.loads(data)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38180916

复制
相关文章

相似问题

将大量数据索引到弹性搜索中

21

将数据上传到弹性搜索时出错

14

将数据发送到弹性搜索时出错

15

将数据从pig加载到弹性搜索

20

将数据从sql server加载到弹性搜索。

13
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文