I have a requirement of creating kibana visualization when a user writes a query like "apache logs for March". I want it to happen dynamically using Python script.
I've tried submitting Kibana JSON request through Elasticsearch's .kibana index and it worked if "query" value is static.
import config
from elasticsearch import Elasticsearch,RequestsHttpConnection
es=Elasticsearch(hosts=[{'host':config.hostName,'port':config.port}],http_auth=
(config.userName,config.password),connection_class=RequestsHttpConnection)
feeds = es.index(index=".kibana",doc_type="visualization", body={
"title": "test kibana1",
"visState": """{"aggs":[{"enabled":true,"id":"1","params":
{},"schema":"metric","type":"count"},{"enabled":true,"id":"2","params"
{"customInterval":"2h","extended_bounds"
{},"field":"@timestamp","interval":"d","min_doc_count":1},"schema":"segment","type":"d
ate_histogram"}],"listeners":{},"params"
{"addLegend":true,"addTooltip":true,"isDonut":false,"legendPosition":"right"},
"title":"test
kibana1","type":"pie"}""",
"uiStateJSON": "{}",
"description": "",
"version": 1,
"kibanaSavedObjectMeta": {
"searchSourceJSON": """{"index":"logstash-yyyy.mm.dd","query":{"match_all":
{}},"filter":[{"$state":{"store":"appState"},"meta":
{"alias":null,"disabled":false,"index":"logstash-
yyyy.mm.dd","key":"message","negate":false,"type":"phrase","value":”apache logs for
march”},"query":{"match":{"message":{"query":”apache logs for march”}}}}]}"""
}
})
print(feeds)
After executing this I am able to see the visualization in Kibana.
But I am aiming to pass string user input to this "query" parameter for which I am getting visualization created message but it's just creating a name for the visualization on Kibana side because it is not accepting the variable which I am trying to pass.
import config
from elasticsearch import Elasticsearch,RequestsHttpConnection
es=Elasticsearch(hosts=[{'host':config.hostName,'port':config.port}],http_auth=
(config.userName,config.password),connection_class=RequestsHttpConnection)
post = input("Enter post:")
feeds = es.index(index=".kibana",doc_type="visualization", body= {
"title": "test kibana1",
"visState": """{"aggs":[{"enabled":true,"id":"1","params":
{},"schema":"metric","type":"count"},{"enabled":true,"id":"2","params":
{"customInterval":"2h","extended_bounds":
{},"field":"@timestamp","interval":"d","min_doc_count":1},"schema":"segment",
"type":"date_histogram"}],"listeners":{},"params":
{"addLegend":true,"addTooltip":true,"isDonut":false,"legendPosition":"right"},
"title":"test kibana1","type":"pie"}""",
"uiStateJSON": "{}",
"description": "",
"version": 1,
"kibanaSavedObjectMeta": {
"searchSourceJSON": """{"index":"logstash-yyyy.mm.dd","query":{"match_all":
{}},"filter":[{"$state":{"store":"appState"},"meta":
{"alias":null,"disabled":false,"index":"logstash-
yyyy.mm.dd","key":"message","negate":false,"type":"phrase","value":post},"query":
{"match":{"message":{"query":post}}}}]}"""
}
})
Is there any way to achieve this? Please help.