导语:
本文主要介绍了关于Python Elasticsearch DSL如何使用的相关知识,希望可以帮到处于编程学习途中的小伙伴
1、连接Es:
import elasticsearch
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=" 39225 5686 ", 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()
本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。
本文为原创文章,版权归知行编程网所有,欢迎分享本文,转载请保留出处!
你可能也喜欢
- ♥ python中的-1是什么意思08/27
- ♥ python列表添加和删除方法09/19
- ♥ 什么是python链表12/12
- ♥ python有什么语法糖?01/03
- ♥ python创建堆的方法有哪些01/13
- ♥ 如何提高python的计算速度?11/12
内容反馈