# Mapping a JSON fields

**URL:** <https://discuss.elastic.co/t/mapping-a-json-fields/67927>\
**Category:** Kibana\
**Created:** [December 3, 2016, 2:57pm UTC](https://discuss.elastic.co/t/mapping-a-json-fields/67927 "2016-12-03T14:57:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guillaume\_Ayad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guillaume_ayad/32/13569_2.png) [@Guillaume\_Ayad](https://discuss.elastic.co/u/Guillaume_Ayad)\
**Post date:** [December 3, 2016, 2:57pm UTC](https://discuss.elastic.co/t/mapping-a-json-fields/67927/1 "2016-12-03T14:57:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![LeeDr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leedr/32/9289_2.png) [@LeeDr](https://discuss.elastic.co/u/LeeDr)\
**Post date:** [December 5, 2016, 4:09pm UTC](https://discuss.elastic.co/t/mapping-a-json-fields/67927/2 "2016-12-05T16:09:59Z")

</div>

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;

 ![](https://us1.discourse-cdn.com/elastic/original/2X/2/26c3cca84f7ac2aaaf29fbc972a5a48b84acc78e.png)

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`;

```auto
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;

```auto
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;

 ![](https://us1.discourse-cdn.com/elastic/original/2X/6/6e2b56e22122ff6b707764d0140a62b88e8f3d0f.png)

And this shows fields like this (notice the last\_update is a date field, and the position is a geo\_point);

 ![](https://us1.discourse-cdn.com/elastic/original/2X/8/8ff3a73919da69944ba12273c086fc42593997bf.png)

I can search for strings like `station`;

 ![](https://us1.discourse-cdn.com/elastic/original/2X/1/1e659d7a221ec3949a676a8eb4e46694e5d45eb5.png)

And I can create a Tile Map using the `position`;

 ![](https://us1.discourse-cdn.com/elastic/original/2X/e/e7a4e2826760290e5e521779ccf3c885df6331b3.jpg)

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

Regards,  
Lee

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 2, 2017, 4:10pm UTC](https://discuss.elastic.co/t/mapping-a-json-fields/67927/3 "2017-01-02T16:10:15Z")

</div>

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