我可以通过以下curl请求获得所需的结果。但是在使用python请求时它无法正常工作。我之前没有使用过弹性搜索,所以这可能是一个基本问题。
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-code片段: -
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
答案 0 :(得分:3)
试试这个,
resp=requests.get(elasticsearch_url,data=json.dumps(data_payload),headers=headers)
data=resp.json()
答案 1 :(得分:0)
我错过了uri中的_search。感谢您的回复。