• 技术文章 >Python技术 >Python基础教程

    Python Elasticsearch DSL如何使用

    小妮浅浅小妮浅浅2021-06-09 09:55:00原创3510

    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()

    以上就是Python Elasticsearch DSL的使用,希望对大家有所帮助。更多Python学习指路:python基础教程

    本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

    专题推荐:python elasticsearchdsl
    品易云
    上一篇:Python脚本如何指定文件 下一篇:Python中deque的操作整理

    相关文章推荐

    • Elasticsearch基本介绍及其与Python的对接实现• Elasticsearch与Python的对接实现• python中elasticsearch是什么?• elasticsearch如何安装?• Java语言开发中elasticsearch如何安装?

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网