Mapping a JSON fields

Hello,
I found a JSON file and as I want to load its data in Kibana, I first need to set up a mapping for the fields in Elasticsearch, am I right ?

{
  "number": 123,
  "contract_name" : "Paris",
  "name": "nom station",
  "address": "adresse indicative",
  "position": {
    "lat": 48.862993,
    "lng": 2.344294
  },
  "banking": true,
  "bonus": false,
  "status": "OPEN",
  "bike_stands": 20,
  "available_bike_stands": 15,
  "available_bikes": 5,
  "last_update": <timestamp>
}

Is there a tool that generates automatically a mapping field that I can then input in the console ?
I am very new and very interested in making smart KPI for my city, thanks for your help.
Best regards,
Guillaume

Hi Guillaume,

I started off my just loading this doc as-is with a fake last_update timestamp. Then I create an index pattern in Kibana, and this is the resulting default mapping;

This is probably pretty good just using the defaults, but there's a few issues.
1). If you want to use that "position" as a geopoint so that you can use the Kibana Tile Map visualization we'll have to create mapping for that.
2). You probably want the last_update to be a date field you can use in Kibana for time-based results. So I think you need a mapping for that also.

I created this mapping for an index named test7 and a type my_type;

PUT test7
{
  "mappings": {
    "my_type": {
      "properties": {
        "last_update": {
          "type":   "date",
          "format": "yyyy-MM-dd HH:mm:ss"
        },
        "position": {
          "type": "geo_point"
        }
      }
    }
  }
}

And I PUT your one doc using the Kibana Dev Tools console like this;

PUT /test7/my_type/123
{
  "number": 123,
  "contract_name" : "Paris",
  "name": "nom station",
  "address": "adresse indicative",
  "position": {
    "lat": 48.862993,
    "lon": 2.344294
  },
  "banking": true,
  "bonus": false,
  "status": "OPEN",
  "bike_stands": 20,
  "available_bike_stands": 15,
  "available_bikes": 5,
  "last_update": "2016-12-05 9:32:00"
}

NOTE that I had to change your position.lng to position.lon. And I used a PUT with your number field instead of a POST. This lets you update docs in Elasticsearch using that number (vs automatic index ID generation).

Now I can create an index pattern in Kibana like;

And this shows fields like this (notice the last_update is a date field, and the position is a geo_point);

I can search for strings like station;

And I can create a Tile Map using the position;

If you want to automatic last_update timestamp, the method depends on what version of Elasticsearch you are using.

Regards,
Lee

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.