Elasticsearch安装和使用

网友投稿 576 2023-02-13

本站部分文章、图片属于网络上可搜索到的公开信息,均用于学习和交流用途,不能代表睿象云的观点、立场或意见。我们接受网民的监督,如发现任何违法内容或侵犯了您的权益,请第一时间联系小编邮箱jiasou666@gmail.com 处理。

Elasticsearch安装和使用

安装 Elasticsearch

加入 Elasticsearch 官方源后安装 elasticsearch:

加入到系统启动文件并启动 elasticsearch 服务,用 curl 测试一下安装是否成功:

1
2
3
4
5
$sudo/usr/share/elasticsearch/bin/plugin-ielasticsearch/marvel/latest
$sudo/etc/init.d/elasticsearch restart
*Stopping Elasticsearch Server[OK]
*Starting Elasticsearch Server[OK]

和 MongoDB 一样,我们一般用程序和 Elasticsearch 交互,Elasticsearch 也支持多种语言的客户端驱动,这里仅安装 Python 驱动,其他语言可以参考官方文档。

1
2
$sudo apt-get install python-pip
$sudo pip install elasticsearch

写个简单程序把 gene_info.txt 的数据导入到 Elasticsearch:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os,os.path,sys,re
import csv,time,string
from datetime import datetime
from elasticsearch import Elasticsearch
def import_to_db():
data=csv.reader(open('gene_info.txt','rb'),delimiter='\t')
data.next()
es=Elasticsearch()
forrow indata:
doc={
'tax_id':row[0],
'GeneID':row[1],
'Symbol':row[2],
'LocusTag':row[3],
'Synonyms':row[4],
'dbXrefs':row[5],
'chromosome':row[6],
'map_location':row[7],
'description':row[8],
'type_of_gene':row[9],
'Symbol_from_nomenclature_authority':row[10],
'Full_name_from_nomenclature_authority':row[11],
'Nomenclature_status':row[12],
'Other_designations':row[13],
'Modification_date':row[14]
}
res=es.index(index="gene",doc_type='gene_info',body=doc)
def main():
import_to_db()
if__name__=="__main__":
main()
上一篇:it运维外包服务(it外包)
下一篇:性能压力测试(性能压力测试怎么做)
相关文章

 发表评论

评论列表