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))
  • 相关阅读:
    centos6和centos7网卡修改
    centos7.4编译安装LNMP
    centos7yum安装LNMP
    jira搭建
    centos6.9编译安装LNMP
    监控命令命令
    linux设置命令历史的时间戳
    zabbix3.0安装
    Mysql(centos7) 主从搭建
    Android 利用剪切板(clipboardManager )实现数据传递
  • 原文地址:https://www.cnblogs.com/hixiaowei/p/11691010.html
Copyright © 2011-2022 走看看