# BulkRequest failed when handle JSON data

**URL:** <https://discuss.elastic.co/t/bulkrequest-failed-when-handle-json-data/368611>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [October 10, 2024, 9:13am UTC](https://discuss.elastic.co/t/bulkrequest-failed-when-handle-json-data/368611 "2024-10-10T09:13:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChatLee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chatlee/32/125019_2.png) [@ChatLee](https://discuss.elastic.co/u/ChatLee)\
**Post date:** [October 10, 2024, 9:13am UTC](https://discuss.elastic.co/t/bulkrequest-failed-when-handle-json-data/368611/1 "2024-10-10T09:13:32Z")

</div>

Hi all,

We want to index data into the ES with bulk api in the java client, the dependency is:  
elasticsearch-java: 8.13.2

the source data is a JSON string like this:

```auto
t String createDoc1 = "{"
              + " \"learning_item_rating\": 4.5,"
              + " \"learning_item_title\": \"Java 101\","
              + " \"learning_item_classification\": \"Program\","
              + " \"learning_item_rating_count\": 10,"
              + " \"learning_item_id\": \"001\""
              + " }";

JsonpMapper jsonpMapper = ES_WRITE_CLIENT._transport().jsonpMapper();
              JsonProvider jsonProvider = jsonpMapper.jsonProvider();
              JsonData doc = JsonData.from(jsonProvider.createParser(new StringReader(createDoc1)), jsonpMapper);
              bulkBuilder.operations(op->op.create(item -> item.index("my_index").id("dod_id").document(doc)));

```

But the request failed with this error:  
ErrorCause: {"type":"document\_parsing\_exception","reason":"[1:24] object mapping for [learning\_item\_title] tried to parse field [learning\_item\_title] as object, but found a concrete value"}.

We tried with this solution:

```auto
bulkBuilder.operations(op->op.create(item -> item.index("my_index").withJson(new StringReader(createDoc1))));

```

but this solution failed because of this error:  
java.lang.IllegalArgumentException: Class class co.elastic.clients.elasticsearch.core.bulk.CreateOperation cannot be read from JSON  
at co.elastic.clients.util.WithJsonObjectBuilderBase.withJson(WithJsonObjectBuilderBase.java:46)

any ideas about how to fix this issue?

thanks

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [October 10, 2024, 9:26am UTC](https://discuss.elastic.co/t/bulkrequest-failed-when-handle-json-data/368611/2 "2024-10-10T09:26:38Z")

</div>

Look at the mappings for the index you are trying to index into using the [get mapping API](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html). It seems the field `learning_item_title`, possibly due to earlier documents or a static mapping, is mapped as an object. This means that trying to index a string for this field results in a mapping conflict.

---

<div class="post-metadata">

**Author:** ![ChatLee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chatlee/32/125019_2.png) [@ChatLee](https://discuss.elastic.co/u/ChatLee)\
**Post date:** [October 10, 2024, 9:32am UTC](https://discuss.elastic.co/t/bulkrequest-failed-when-handle-json-data/368611/3 "2024-10-10T09:32:15Z")

</div>

this is the learning\_item\_title's mapping setup:

```auto
{
  "mappings": {
    "dynamic": "strict",
    "properties": {
    "learning_item_title": {
        "properties": {
          "de_DE": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "doc_values": false,
                "normalizer": "lowercase"
              },
              "sayt": {
                "type": "search_as_you_type",
                "doc_values": false,
                "max_shingle_size": 3,
                "analyzer": "rebuilt_german_delimiter"
              },
              "sort": {
                "type": "icu_collation_keyword",
                "index": false,
                "language": "de",
                "country": "DE"
              }
            },
            "analyzer": "rebuilt_german_delimiter",
            "index_prefixes": {
              "min_chars": 2,
              "max_chars": 19
            }
          },
          "en_US": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "doc_values": false,
                "normalizer": "lowercase"
              },
              "sayt": {
                "type": "search_as_you_type",
                "doc_values": false,
                "max_shingle_size": 3,
                "analyzer": "rebuilt_english_delimiter"
              },
              "sort": {
                "type": "icu_collation_keyword",
                "index": false,
                "language": "en",
                "country": "US"
              }
            },
            "analyzer": "rebuilt_english_delimiter",
            "index_prefixes": {
              "min_chars": 2,
              "max_chars": 19
            }
          }}}}}}

```

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [October 10, 2024, 9:48am UTC](https://discuss.elastic.co/t/bulkrequest-failed-when-handle-json-data/368611/4 "2024-10-10T09:48:58Z")

</div>

That is as expected. It has fields specified underneath, e.g. `de_DE` and `en_US`, which means that it is an object and can not take strings. You will need to change the structure of the document you try to index.

---

<div class="post-metadata">

**Author:** ![ChatLee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chatlee/32/125019_2.png) [@ChatLee](https://discuss.elastic.co/u/ChatLee)\
**Post date:** [October 11, 2024, 2:44am UTC](https://discuss.elastic.co/t/bulkrequest-failed-when-handle-json-data/368611/5 "2024-10-11T02:44:44Z")

</div>

got it, let me try again.

By the way, does the bulkrequest support the script type under the Update operation? If so, is there any documents about how to setup script content in the bulkrequest (the source data still come from JSON like:'{'script:'xxxxx'}')?
