title: Elasticsearch High Level Rest Client - java Map with typed (sub) fields - dates, numbers etc
body: <p><em>(clarification copied from a comment)</em></p>
  
  <p>I have a <code>java.util.Map</code> that has different key value pairs, and some of the values are dates, some numbers, some are strings, and some are also <code>java.util.Map</code>s that can also contain all kinds of above mentioned types. I am able to put it into the index, I see that the elasticsearch mapping is created automatically with correct field types, now I want to retrieve that <code>Map</code> and see dates, numbers, strings and nested <code>Map</code>s instead of what I currently have - just strings and Maps</p>
  
  <p>Further story:</p>
  
  <p>I'm putting a <code>java.util.Map</code> in Elasticsearch using the following code:</p>
  
  <pre><code>public void putMap(String key, Map&lt;String, ?&gt; value) {
      try {
          IndexRequest ir = Requests.indexRequest(_index)
                  .id(key)
                  .type("doc")
                  .source(value);
  
          Factory.DB.index(ir); // the high level rest client here
  
      } catch (IOException ex) {
          throw new RuntimeException(ex);
      }
  }
  </code></pre>
  
  <p>I am not able to create mappings explicitly as per my task. </p>
  
  <p>For one of my indices it has created the mapping like this, which is quite fine:</p>
  
  <pre><code>{
  "rex": {
  "mappings": {
    "doc": {
      "properties": {
        "variables": {
          "properties": {
            "customer": {
              "properties": {
                "accounts": {
                  "properties": {
                    "dateOpen": {
                      "type": "date"
                    },
                    "id": {
                      "type": "text",
                      "fields": {
                        "keyword": {
                          "type": "keyword",
                          "ignore_above": 256
                        }
                      }
                    }
                  }
                },
                "dateOfBirth": {
                  "type": "date"
                },
                "firstName": {
                  "type": "text",
                  "fields": {
                    "keyword": {
                      "type": "keyword",
                      "ignore_above": 256
                    }
                  }
                },
                "id": {
                  "type": "text",
                  "fields": {
                    "keyword": {
                      "type": "keyword",
                      "ignore_above": 256
                    }
                  }
                },
  
                "lastName": {
                  "type": "text",
                  "fields": {
                    "keyword": {
                      "type": "keyword",
                      "ignore_above": 256
                    }
                  }
                },
                "middleName": {
                  "type": "text",
                  "fields": {
                    "keyword": {
                      "type": "keyword",
                      "ignore_above": 256
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  }
  }
  </code></pre>
  
  <p>Now I am retrieving my structure back with the following code,</p>
  
  <pre><code>public Map&lt;String, ?&gt; getMap(String key) {
      try {
  
          GetRequest gr = new GetRequest(_index, "doc", key);
  
          try {
              GetResponse response = Factory.DB.get(gr);
  
              if (!response.isExists()) {
                  return null;
              }
  
              Map&lt;String, ?&gt; ret = response.getSourceAsMap();
  
              return ret;
          } catch (ElasticsearchStatusException ee) {
              if (ee.status().getStatus() == RestStatus.NOT_FOUND.getStatus()) {
                  return null;
              } else {
                  throw new RuntimeException(ee);
              }
          }
  
      } catch (IOException ex) {
          throw new RuntimeException(ex);
      }
  }
  </code></pre>
  
  <p>The dates are returned as strings like "1957-04-29T00:00:00.000Z"</p>
  
  <p>There's no Java object to map this document to as I have only Maps of Maps/Lists/values.</p>
  
  <p>How do I make the Java Rest Client respect the mapping the Elasticsearch created for the index? <code>response.getFields()</code> returns empty map. </p>
  
  <p>In case it is impossible (like 'source is json/strings by design' etc etc), I am ready to retrieve the mapping in the most convenient form possible and walk through the result by myself. The code to retrieve elasticsearch mapping will be appreciated.</p>
  
  <p>Big thank you!</p>