elasticsearch的python接口使用

来源:互联网 发布:php导出数据到excel 编辑:程序博客网 时间:2024/06/05 04:35

elasticsearch-py

Installationedit

It can be installed with pip:

pip install elasticsearch

The legacy version for Elasticsearch version 2.x can be installed with pip:

pip install elasticsearch2

Current development happens in the master branch.

The master branch is the only branch under current development andis used to track all the changes for Elasticsearch 5.x and beyond.

Elasticsearch version 2.x is not longer under active development.We will only backport severe bug fixes.

The recommended way to set your requirements in your setup.py orrequirements.txt is:

    # Elasticsearch 5.x    elasticsearch>=5.0.0,<6.0.0    # Elasticsearch 2.x    elasticsearch2

Simple use-case:

>>> from datetime import datetime>>> from elasticsearch import Elasticsearch# by default we connect to localhost:9200>>> es = Elasticsearch()# datetimes will be serialized>>> es.index(index="my-index", doc_type="test-type", id=42, body={"any": "data", "timestamp": datetime.now()}){u'_id': u'42', u'_index': u'my-index', u'_type': u'test-type', u'_version': 1, u'ok': True}# but not deserialized>>> es.get(index="my-index", doc_type="test-type", id=42)['_source']{u'any': u'data', u'timestamp': u'2013-05-12T19:45:31.804229'}

原创粉丝点击