Curl 通过python请求进行elastichsearch查询时出错
我可以通过以下curl请求获得所需的结果。但是当使用python请求时,它不起作用。我以前没有使用过elasticsearch,所以这可能是一个基本问题Curl 通过python请求进行elastichsearch查询时出错,curl,elasticsearch,python-requests,Curl,elasticsearch,Python Requests,我可以通过以下curl请求获得所需的结果。但是当使用python请求时,它不起作用。我以前没有使用过elasticsearch,所以这可能是一个基本问题 curl -XGET 'http://something.someone.com:9200/logstash-2018.02.09/_search?pretty' -d'{ "query": { "filtered": { "query": { "query_string": {
curl -XGET 'http://something.someone.com:9200/logstash-2018.02.09/_search?pretty' -d'{ "query": {
"filtered": {
"query": {
"query_string": {
"query": "host: \"pod1-cph3.someone.com\" AND facility: user AND severity: info AND ident:web20 AND message: Write",
"analyze_wildcard": true
}
}
}
}
}'
python代码段:-
headers ={'Content-Type': 'application/json'}
elasticsearch_url="http://something.someone.com:9200/logstash-{}/".format(current_date)
data_payload= {
"query": {
"filtered": {
"query": {
"query_string": {
"query": "host: \"pod1-cph3.someone.com\" AND facility: user AND severity: info AND ident:web20 AND message: Write",
"analyze_wildcard": "true"
}
}
}
}
}
resp=requests.get(elasticsearch_url,data=json.dumps(data_payload),headers=headers)
print resp.content
请注意,这不是我的愿望输出。
产量相当长。我粘贴了其中的一部分:-
{"logstash-2018.02.09":{"aliases":{},"mappings":{"fluentd":{"properties":{"@timestamp":{"type":"date","format":"strict_date_optional_time||epoch_millis"},"CODE_FILE":{"type":"string"},"CODE_FUNC":{"type":"string"},"CODE_FUNCTION":{"type":"string"},"CODE_LINE":{"type":"string"},"CONFIG_FILE":{"type":"string"},"CONFIG_LINE":{"type":"str
试试这个
resp=requests.get(elasticsearch_url,data=json.dumps(data_payload),headers=headers)
data=resp.json()
试试这个
resp=requests.get(elasticsearch_url,data=json.dumps(data_payload),headers=headers)
data=resp.json()
我错过了uri中的搜索。谢谢你的回复。我错过了uri中的搜索。感谢您的回复。您收到的错误是什么?@enator查看编辑您收到的错误是什么?@enator查看编辑