@Test
  public void testIpMultiField() throws Exception {
    assertAcked(
        client()
            .admin()
            .indices()
            .prepareCreate("my-index")
            .addMapping("my-type", createMappingSource("ip")));

    GetMappingsResponse getMappingsResponse =
        client().admin().indices().prepareGetMappings("my-index").get();
    MappingMetaData mappingMetaData = getMappingsResponse.mappings().get("my-index").get("my-type");
    assertThat(mappingMetaData, not(nullValue()));
    Map<String, Object> mappingSource = mappingMetaData.sourceAsMap();
    Map aField = ((Map) XContentMapValues.extractValue("properties.a", mappingSource));
    assertThat(aField.size(), equalTo(2));
    assertThat(aField.get("type").toString(), equalTo("ip"));
    assertThat(aField.get("fields"), notNullValue());

    Map bField = ((Map) XContentMapValues.extractValue("properties.a.fields.b", mappingSource));
    assertThat(bField.size(), equalTo(2));
    assertThat(bField.get("type").toString(), equalTo("string"));
    assertThat(bField.get("index").toString(), equalTo("not_analyzed"));

    client()
        .prepareIndex("my-index", "my-type", "1")
        .setSource("a", "127.0.0.1")
        .setRefresh(true)
        .get();
    CountResponse countResponse =
        client().prepareCount("my-index").setQuery(matchQuery("a.b", "127.0.0.1")).get();
    assertThat(countResponse.getCount(), equalTo(1l));
  }
  @Test
  public void updateMappingWithoutTypeMultiObjects() throws Exception {
    client()
        .admin()
        .indices()
        .prepareCreate("test")
        .setSettings(
            ImmutableSettings.settingsBuilder()
                .put("index.number_of_shards", 1)
                .put("index.number_of_replicas", 0))
        .execute()
        .actionGet();
    client()
        .admin()
        .cluster()
        .prepareHealth()
        .setWaitForEvents(Priority.LANGUID)
        .setWaitForGreenStatus()
        .execute()
        .actionGet();

    PutMappingResponse putMappingResponse =
        client()
            .admin()
            .indices()
            .preparePutMapping("test")
            .setType("doc")
            .setSource(
                "{\"_source\":{\"enabled\":false},\"properties\":{\"date\":{\"type\":\"integer\"}}}")
            .execute()
            .actionGet();

    assertThat(putMappingResponse.isAcknowledged(), equalTo(true));

    GetMappingsResponse getMappingsResponse =
        client().admin().indices().prepareGetMappings("test").execute().actionGet();
    assertThat(
        getMappingsResponse.mappings().get("test").get("doc").source().toString(),
        equalTo(
            "{\"doc\":{\"_source\":{\"enabled\":false},\"properties\":{\"date\":{\"type\":\"integer\"}}}}"));
  }
  @Test
  public void testMultiFields() throws Exception {
    assertAcked(
        client()
            .admin()
            .indices()
            .prepareCreate("my-index")
            .addMapping("my-type", createTypeSource()));

    GetMappingsResponse getMappingsResponse =
        client().admin().indices().prepareGetMappings("my-index").get();
    MappingMetaData mappingMetaData = getMappingsResponse.mappings().get("my-index").get("my-type");
    assertThat(mappingMetaData, not(nullValue()));
    Map<String, Object> mappingSource = mappingMetaData.sourceAsMap();
    Map titleFields =
        ((Map) XContentMapValues.extractValue("properties.title.fields", mappingSource));
    assertThat(titleFields.size(), equalTo(1));
    assertThat(titleFields.get("not_analyzed"), notNullValue());
    assertThat(
        ((Map) titleFields.get("not_analyzed")).get("index").toString(), equalTo("not_analyzed"));

    client()
        .prepareIndex("my-index", "my-type", "1")
        .setSource("title", "Multi fields")
        .setRefresh(true)
        .get();

    SearchResponse searchResponse =
        client().prepareSearch("my-index").setQuery(matchQuery("title", "multi")).get();
    assertThat(searchResponse.getHits().totalHits(), equalTo(1l));
    searchResponse =
        client()
            .prepareSearch("my-index")
            .setQuery(matchQuery("title.not_analyzed", "Multi fields"))
            .get();
    assertThat(searchResponse.getHits().totalHits(), equalTo(1l));

    assertAcked(
        client()
            .admin()
            .indices()
            .preparePutMapping("my-index")
            .setType("my-type")
            .setSource(createPutMappingSource())
            .setIgnoreConflicts(
                true) // If updated with multi-field type, we need to ignore failures.
        );

    getMappingsResponse = client().admin().indices().prepareGetMappings("my-index").get();
    mappingMetaData = getMappingsResponse.mappings().get("my-index").get("my-type");
    assertThat(mappingMetaData, not(nullValue()));
    mappingSource = mappingMetaData.sourceAsMap();
    assertThat(
        ((Map) XContentMapValues.extractValue("properties.title", mappingSource)).size(),
        equalTo(2));
    titleFields = ((Map) XContentMapValues.extractValue("properties.title.fields", mappingSource));
    assertThat(titleFields.size(), equalTo(2));
    assertThat(titleFields.get("not_analyzed"), notNullValue());
    assertThat(
        ((Map) titleFields.get("not_analyzed")).get("index").toString(), equalTo("not_analyzed"));
    assertThat(titleFields.get("uncased"), notNullValue());
    assertThat(
        ((Map) titleFields.get("uncased")).get("analyzer").toString(), equalTo("whitespace"));

    client()
        .prepareIndex("my-index", "my-type", "1")
        .setSource("title", "Multi fields")
        .setRefresh(true)
        .get();

    searchResponse =
        client().prepareSearch("my-index").setQuery(matchQuery("title.uncased", "Multi")).get();
    assertThat(searchResponse.getHits().totalHits(), equalTo(1l));
  }