一:基本配置使用
1. 连接:
ee = elasticsearch(['1.1.1.148:9200'])
2.建立index:
>>> ee.indices.create(index='webfingle',ignore=400) 400表示如果存在该名称的index就直接忽略
{u'acknowledged': True}
3. 删除index:
elasticsearch 说明看大了头,先用最快捷的curl吧
curl -XDELETE 'http://1.1.1.148:9200/.marvel-2015.12.09‘
’‘.marvel-2015.12.09“ 为index
4. 插入数据
def es_insert(e_id,e_ip,e_status,e_server,e_tit):
try:
es = Elasticsearch('1.1.1.148:9200')
#es.indices.create(index='test',ignore=400) ##can use "curl -XDELETE 'http://1.1.1.148:9200/test'" delete test index
s1 = es.index(index='test',doc_type='web-type',id = e_id,body={'ip':e_ip,'status':e_status,'es-type':e_server,'title':e_tit,'times':datetime.now()})
#notice, there body user-defined,what data is you want
print 'Save ok!'
except Exception, e:
print '[Exception is]', e
直接调用插入,怎么爽怎么插,
5. 浏览器查看:
http://localhost:9200/_plugin/marvel/
http://localhost:9200/_plugin/head/
查看某条数据:
http://localhost:9200/test/es-type/11
test : index
es-type : doc-type
11 : id
6. 其他
1) 获取集群健康状况
curl -XGET 'http://localhost:9200/_cluster/health?pretty=true'
2)集群状态
curl -XGET 'http://localhost:9200/_cluster/state?pretty'
curl -XGET 'http://localhost:9200/_cluster/stats?human&pretty'
3)节点状态
curl -XGET 'http://localhost:9200/_nodes/stats?pretty'
curl -XGET 'http://localhost:9200/_nodes/stats/os,process?pretty'
4)本机节点查询
curl -XGET 'localhost:9200/_nodes/_local?pretty'
curl -XGET 'localhost:9200/_nodes/_local/network?pretty'
http://blog.chinaunix.net/uid-532511-id-4854331.html
二:性能方面
1. 指定分片(shard)的数量和副本(replica)的数量,ElasticSearch在创建索引数据时,最好指定相关的shards
数量和replicas,否则会使用服务器中的默认配置参数shards=5,replicas=1
原因:
1)拥有更多的碎片可以提升索引执行能力
2)拥有更多的副本能够提升搜索执行能力以及集群能力
浙公网安备 33010602011771号