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))
  • 相关阅读:
    agc027D
    agc027E
    agc036D
    牛客挑战赛43 D-数组操作
    CF587F. Duff is Mad
    CF578F. Mirror Box
    CF708D. Incorrect Flow
    agc022D
    2020.12.16 模拟赛x+1
    Mybatis Plus——[Could not set property 'id' of '***' with value]解决方案
  • 原文地址:https://www.cnblogs.com/hixiaowei/p/11691010.html
Copyright © 2011-2022 走看看