Centos安装pip和elasticsearch模块基本使用
CentOS安装python包管理安装工具pip的方法如下:
# wget --no-check-certificate https://github.com/pypa/pip/archive/1.5.5.tar.gz # mv 1.5.5 1.5.5.tar.gz # tar zxf 1.5.5.tar.gz # cd pip-1.5.5/ # python setup.py install 验证: # pip -V pip 1.5.5 from /usr/lib/python2.6/site-packages/pip-1.5.5-py2.6.egg (python 2.6)
安装elasticsearch模块如下:
# pip install elasticsearch
使用示例如下:
>>> from datetime import datetime [quote]>> from elasticsearch import Elasticsearch[/quote] # 默认情况下我们连接 localhost:9200 [quote]>> es = Elasticsearch()[/quote] # datetimes 将序列化 [quote]>> 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}[/quote] # 但不是反序列化 [quote]>> 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'}[/quote]