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))
用一个例子来演示会更加清晰