适用于curl的Python等效代码,包括弹性搜索查询

时间:2018-07-22 21:42:09

标签: python-3.x mongodb elasticsearch python-requests

什么是等效的python请求代码:

curl -XGET "https://acd.int.com:9100/abc%2A/search" -H 'Content-Type: application/json' -k -u bfire:XXX -d'
{
"query": {
"query_string": {
"query": "@timestamp:[2018-06-29T06:47:40.000Z TO *]"
}
},
"size": 1000
}
'|json_pp

1 个答案:

答案 0 :(得分:0)

通过https://curl.trillworks.com找到了答案,尽管需要在开发服务器上对其进行测试...

import requests

headers = {
    'Content-Type': 'application/json',
}

data = '\n{\n"query": {\n"query_string": {\n"query": "@timestamp:[2018-06-29T06:47:40.000Z TO *]"\n}\n},\n"size": 1000\n}\n|json_pp'

response = requests.post('https://acd.int.com:9100/abc%2A/search', headers=headers, data=data, verify=False, auth=('bfire', 'XXX'))