热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

pythonapielasticsearch_elasticsearchpython批量api(elasticsearchpy)

我的代码:fromelasticsearchimportElasticsearchesElasticsearch()doc\n{host:logsqa,pa

我的代码:from elasticsearch import Elasticsearch

es = Elasticsearch()

doc = '''\n {"host":"logsqa","path":"/logs","message":"test test","@timestamp":"2014-10-02T10:11:25.980256","tags":["multiline","mydate_0.005"]} \n'''

result = es.bulk(index="logstash-test", doc_type="test", body=doc)

错误是:No handlers could be found for logger "elasticsearch"

Traceback (most recent call last):

File "./log-parser-perf.py", line 55, in

insertToES()

File "./log-parser-perf.py", line 46, in insertToES

res = es.bulk(index="logstash-test", doc_type="test", body=doc)

File "/usr/local/lib/python2.7/dist-packages/elasticsearch-1.0.0-py2.7.egg/elasticsearch/client/utils.py", line 70, in _wrapped

return func(*args, params=params, **kwargs)

File "/usr/local/lib/python2.7/dist-packages/elasticsearch-1.0.0-py2.7.egg/elasticsearch/client/__init__.py", line 570, in bulk

params=params, body=self._bulk_body(body))

File "/usr/local/lib/python2.7/dist-packages/elasticsearch-1.0.0-py2.7.egg/elasticsearch/transport.py", line 274, in perform_request

status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore)

File "/usr/local/lib/python2.7/dist-packages/elasticsearch-1.0.0-py2.7.egg/elasticsearch/connection/http_urllib3.py", line 57, in perform_request

self._raise_error(response.status, raw_data)

File "/usr/local/lib/python2.7/dist-packages/elasticsearch-1.0.0-py2.7.egg/elasticsearch/connection/base.py", line 83, in _raise_error

raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)

elasticsearch.exceptions.TransportError: TransportError(500, u'ActionRequestValidationException[Validation Failed: 1: no requests added;]')

为POST call生成的url是/logstash-test/test/_bulk

柱体是:{"host":"logsqa","path":"/logs","message":"test

test","@timestamp":"2014-10-02T10:11:25.980256","tags":["multiline","mydate_0.005"]}

所以我用手把车卷起来:

这种卷曲不起作用:> curl -XPUT http://localhost:9200/logstash-test/test2/_bulk -d

> '{"host":"logsqa","path":"/logs","message":"test

> test","@timestamp":"2014-10-02T10:11:25.980256","tags":["multiline","mydate_0.005"]}

> '

>

> {"error":"ActionRequestValidationException[Validation Failed: 1: no requests added;]","status":500}

所以错误是部分正常的,但是我确实希望elasticsearch.bulk()能够正确地管理输入参数。

pythonf函数是:bulk(*args, **kwargs)

:arg body: The operation definition and data (action-data pairs), as

either a newline separated string, or a sequence of dicts to

serialize (one per row).

:arg index: Default index for items which don't provide one

:arg doc_type: Default document type for items which don't provide one

:arg consistency: Explicit write consistency setting for the operation

:arg refresh: Refresh the index after performing the operation

:arg routing: Specific routing value

:arg replication: Explicitly set the replication type (default: sync)

:arg timeout: Explicit operation timeout



推荐阅读
author-avatar
清洁剂没看见家门口_200
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有