zoukankan      html  css  js  c++  java
  • python 配合 es 查询数据

    1.python脚本

    [root@do1cloud03 ~]# cat  python-es.py
    #!/usr/bin/env python3
    
    from elasticsearch import Elasticsearch
    from json import dumps
    
    es = Elasticsearch(
        ['127.0.0.1:9200'],
        # 认证信息
        # http_auth=('elastic', 'elastic')
    )
    
    #print(es.ping())
    #print(es.cat.indices())
    
    response = es.search(
        index="logstash-2019.10.17", # 索引名
        body={             # 请求体
          "query": {       # 关键字,把查询语句给 query
              "bool": {    # 关键字,表示使用 filter 查询,没有匹配度
                    "must": [      # 表示里面的条件必须匹配,多个匹配元素可以放在列表里
                        {
                            "match": {  # 关键字,表示需要匹配的元素
                                #"message": '/mgr/minutes/getMeetingConfigByType.mvc'
                                "message": "/mgr/getRootTree.mvc"
                            }
                        },
                        {
    
                            "match": {
                                 "profile": "prod"
                            }
                        },
                        {
                            "match": {  # 关键字,表示需要匹配的元素
                                #"message": '/mgr/minutes/getMeetingConfigByType.mvc'
                                "message": "耗时"
                            }
                        }
                          ],
                }
            }
      },
    )
    #print(response)
    #for v in response.values():
    #    print(v)
    res_lst = response["hits"]["hits"]
    for i in res_lst:
        print(dumps(i))
  • 相关阅读:
    c博客作业05--指针
    C博客作业04--数组
    C博客作业03--函数
    C博客作业02--循环结构
    C博客作业01--分支、顺序结构
    我的第一篇博客
    DS博客作业05--查找
    DS博客作业04--图
    DS博客作业03--树
    DS博客作业02--栈和队列
  • 原文地址:https://www.cnblogs.com/hixiaowei/p/11691010.html
Copyright © 2011-2022 走看看