python操作elasticsearch(Python Elasticsearch DSL如何使用)
导读:1、连接Es: importelasticsearch es=elasticsearch.Elasticsearch([{...
1 、连接Es:
importelasticsearch es=elasticsearch.Elasticsearch([{host:127.0.0.1,port:9200}])2 、先看一下搜索 ,q 是指搜索内容 ,空格对 q 查询结果没有影响 ,size 指定个数 ,from_ 指定起始位置 ,filter_path 可以指定需要显示的数据 ,如显示在最后的结果中的只有 _id 和 _type 。
res_3=es.search(index="bank",q="Holmes",size=1,from_=1) res_4=es.search(index="bank",q="392255686",size=1000,filter_path=[hits.hits._id,hits.hits._type])3 、根据某个字段查询 ,可以多个查询条件叠加:
s=Search(using=es,index="index-test").query("match",sip="192.168.1.1") s=s.query("match",dip="192.168.1.2") s=s.excute()以上就是Python Elasticsearch DSL的使用 ,希望对大家有所帮助 。更多Python学习指路:Python基础教程
创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!