Hi all,
I wrote a pretty simple python script:
import json
import datetime
from elasticsearch5 import Elasticsearch
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
now = datetime.datetime.now()
INDEX_NAME = 'aggregated-%s' % now.strftime("%Y.%m.%d")
settings = {
"mappings": {
"logs": {
"properties": {
"Tempo medio chiamata (ms)": {
"type": "float"
},
"Numero di chiamate" :{
"type": "integer"
},
"@timestamp" :{
"type" : "date"
}
}
}
}
}
if not es.indices.exists(INDEX_NAME):
es.indices.create(index=INDEX_NAME, ignore=400, body=settings)
res = es.search(body={
"size": 0,
"aggs": {
"services": {
"terms": {
"field": "resource_templatePath.keyword"
},
"aggs": {
"avg_duration": {
"avg": {
"field": "http_durationMs"
}
}
}
}
}
}
)
for f in res['aggregations']['services']['buckets']:
req_body= {
'Function': '%s' % f['key'],
'Numero di chiamate': '%s' % f['doc_count'],
'Tempo medio chiamata (ms)': '%s' % f['avg_duration']['value'],
'@timestamp': now.isoformat()
}
es.index(index=INDEX_NAME, doc_type='logs', body=json.dumps(req_body))
It works fine, and if I query Elastic, result is:
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 4,
"max_score": 1,
"hits": [
{
"_index": "aggregated-2018.04.18",
"_type": "logs",
"_id": "AWLZGC4XTA1Gx7az1yUk",
"_score": 1,
"_source": {
"Function": "GET <ues-mocks>/v1/work-order-activity/{idWorkOrderActivity}/verify-parallel-start",
"Numero di chiamate": "6",
"Tempo medio chiamata (ms)": "205.33333333333334",
"@timestamp": "2018-04-18T16:11:01.902051"
}
},
.
.
Problem is: kibana shows no results (of course, the time interval is not the issue).
If I take away the @timestamp field, and recreate the index pattern it all works fine on kibana, but of course I have no indication about event timing anymore.
Can anyone help me please? I'm stuck with it and I'm losing my mind..
Thank you very much!
Cheers