# getFieldMapping request using java API for elasticsearch

**URL:** <https://discuss.elastic.co/t/getfieldmapping-request-using-java-api-for-elasticsearch/329705>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [April 11, 2023, 5:10am UTC](https://discuss.elastic.co/t/getfieldmapping-request-using-java-api-for-elasticsearch/329705 "2023-04-11T05:10:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shwetanb](https://avatars.discourse-cdn.com/v4/letter/s/8e7dd6/32.png) [@shwetanb](https://discuss.elastic.co/u/shwetanb)\
**Post date:** [April 11, 2023, 5:10am UTC](https://discuss.elastic.co/t/getfieldmapping-request-using-java-api-for-elasticsearch/329705/1 "2023-04-11T05:10:34Z")

</div>

I am trying to replicate below query DSL using java:

```auto
GET /test/_mapping/field/*?include_defaults=true

```

I am using below code to get mappings:

```auto
GetFieldMappingResponse resp = client.indices().getFieldMapping(new GetFieldMappingRequest.Builder()
					.index("test").fields("*").includeDefaults(true).build());

```

When i execute this code I get error:

```auto
co.elastic.clients.json.UnexpectedJsonEventException: Unexpected JSON event 'VALUE_NULL' instead of '[START_OBJECT, KEY_NAME, VALUE_STRING]'

```

If I make "includeDefaults" as "false" in API request, I get results but get error if I make it true.

Below is the response of mentioned DSL if I do it from UI:

```auto
GET /test/_mapping/field/*?include_defaults=true
{
  "shweta-test": {
    "mappings": {
      "_routing": {
        "full_name": "_routing",
        "mapping": {}
      },
      "_doc_count": {
        "full_name": "_doc_count",
        "mapping": {}
      },
      "_index": {
        "full_name": "_index",
        "mapping": {}
      },
      "_feature": {
        "full_name": "_feature",
        "mapping": {}
      },
      "title": {
        "full_name": "title",
        "mapping": {
          "title": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      },
      "_tier": {
        "full_name": "_tier",
        "mapping": {}
      },
      "title.keyword": {
        "full_name": "title.keyword",
        "mapping": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "_ignored": {
        "full_name": "_ignored",
        "mapping": {}
      },
      "_seq_no": {
        "full_name": "_seq_no",
        "mapping": {}
      },
      "pages": {
        "full_name": "pages",
        "mapping": {
          "pages": {
            "type": "long"
          }
        }
      },
      "_nested_path": {
        "full_name": "_nested_path",
        "mapping": {}
      },
      "_data_stream_timestamp": {
        "full_name": "_data_stream_timestamp",
        "mapping": {}
      },
      "_field_names": {
        "full_name": "_field_names",
        "mapping": {}
      },
      "_source": {
        "full_name": "_source",
        "mapping": {}
      },
      "_id": {
        "full_name": "_id",
        "mapping": {}
      },
      "place": {
        "full_name": "place",
        "mapping": {
          "place": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      },
      "place.keyword": {
        "full_name": "place.keyword",
        "mapping": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "_version": {
        "full_name": "_version",
        "mapping": {}
      }
    }
  }
}

```

Could anyone tell me what is missing here?

---

<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:** [May 9, 2023, 5:11am UTC](https://discuss.elastic.co/t/getfieldmapping-request-using-java-api-for-elasticsearch/329705/2 "2023-05-09T05:11:03Z")

</div>

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