How to generate visualization for an item of an array in another array


(Ayotunde Salako) #1

Hello,

I am new to Kibana and I have the data below in JSON format. I need to generate visualiztion for the fuel variable inside the attribute array.

{ "_index": "positions", "_type": "position", "_id": "2727459", "_score": null, "_source": { "id": 2727459, "protocol": "noran", "deviceid": 10, "servertime": "2016-08-08T11:48:56.000Z", "devicetime": "2016-08-08T11:48:53.000Z", "fixtime": "2016-08-08T11:48:53.000Z", "valid": true, "latitude": 6.439499855041504, "longitude": 3.456439971923828, "altitude": 0, "speed": 0, "course": 237, "address": null, "attributes": "{\"alarm\":128,\"io1\":0,\"fuel\":40,\"ip\":\"197.210.225.60\"}", "@version": "1", "@timestamp": "2016-08-08T11:49:00.020Z" }, "fields": { "servertime": [ 1470656936000 ], "fixtime": [ 1470656933000 ], "@timestamp": [ 1470656940020 ], "devicetime": [ 1470656933000 ] }, "sort": [ 1470656936000 ] }

I want to be able to create an histogram visualization of fuel level per hour. Kindly help.


(Lee Drengenberg) #2

Hi,

Please see this documentation on how to add nested data;
https://www.elastic.co/guide/en/elasticsearch/guide/current/nested-mapping.html

I made this very crude test below and I can use the values of the attributes in Kibana. Note that I'm sure this is NOT the correct mapping you would want. This mapping doesn't add a date field so it doesn't allow you to create charts over time. It's just to show how to do the nested attributes.

Lee

curl -XDELETE 'http://elastic:notsecure@localhost:9200/test101'

curl --basic -XPOST 'http://elastic:notsecure@localhost:9200/test101' -d '{
    "settings" : {
        "number_of_shards" : 1
    },
  "mappings": {
    "test": {
      "properties": {
        "attributes": {
          "type": "nested", 
          "properties": {
            "fuel": { "type": "string"  },
            "ip": { "type": "string"  },
            "alarm": { "type": "int" },
            "io1": { "type": "int" }
          }
        }
      }
    }
  }
}'


curl -XPUT 'http://elastic:notsecure@localhost:9200/test101/test/1' -d '{
	"protocol": "noran",
	"deviceid": 10,
	"servertime": "2016-08-08T11:48:56.000Z",
	"devicetime": "2016-08-08T11:48:53.000Z",
	"fixtime": "2016-08-08T11:48:53.000Z",
	"valid": true,
	"latitude": 6.439499855041504,
	"longitude": 3.456439971923828,
	"altitude": 0,
	"speed": 0,
	"course": 237,
	"address": null,
	"attributes": {"alarm":128,"io1":0,"fuel":40,"ip":"197.210.225.60"},
	"@version": "1",
	"@timestamp": "2016-08-08T11:49:00.020Z"
}'

curl -XPUT 'http://elastic:notsecure@localhost:9200/test101/test/2' -d '{
	"protocol": "noran",
	"deviceid": 10,
	"servertime": "2016-08-08T11:48:56.000Z",
	"devicetime": "2016-08-08T11:48:53.000Z",
	"fixtime": "2016-08-08T11:48:53.000Z",
	"valid": true,
	"latitude": 6.439499855041504,
	"longitude": 3.456439971923828,
	"altitude": 0,
	"speed": 0,
	"course": 237,
	"address": null,
	"attributes": {"alarm":121,"io1":0,"fuel":40,"ip":"197.210.225.60"},
	"@version": "1",
	"@timestamp": "2016-08-08T11:49:00.020Z"
}'

curl -XPUT 'http://elastic:notsecure@localhost:9200/test101/test/3' -d '{
	"protocol": "noran",
	"deviceid": 10,
	"servertime": "2016-08-08T11:48:56.000Z",
	"devicetime": "2016-08-08T11:48:53.000Z",
	"fixtime": "2016-08-08T11:48:53.000Z",
	"valid": true,
	"latitude": 6.439499855041504,
	"longitude": 3.456439971923828,
	"altitude": 0,
	"speed": 0,
	"course": 237,
	"address": null,
	"attributes": {"alarm":321,"io1":0,"fuel":40,"ip":"197.210.225.60"},
	"@version": "1",
	"@timestamp": "2016-08-08T11:49:00.020Z"
}'


(system) #3