# Problem when indexing nested object (Elasticsearch 5.6)

**URL:** <https://discuss.elastic.co/t/problem-when-indexing-nested-object-elasticsearch-5-6/116177>\
**Category:** Elasticsearch\
**Created:** [January 19, 2018, 6:55am UTC](https://discuss.elastic.co/t/problem-when-indexing-nested-object-elasticsearch-5-6/116177 "2018-01-19T06:55:00Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phongsatorn.P](https://avatars.discourse-cdn.com/v4/letter/p/7cd45c/32.png) [@Phongsatorn.P](https://discuss.elastic.co/u/Phongsatorn.P)\
**Post date:** [January 19, 2018, 6:55am UTC](https://discuss.elastic.co/t/problem-when-indexing-nested-object-elasticsearch-5-6/116177/1 "2018-01-19T06:55:00Z")

</div>

Hi there,  
I have some problem when i want to index (by using cURL) nested object , assume i have to indices (restaurant\_info and restaurant\_payment) both two indices have nested object. But problem that occured was nested object in restaurant\_info can index to server without error. In contrast, nested object restaurant\_payment can't index to server.

```
Here's restaurant_info mappings
         {
           "mappings": {
             "fashion_brand_info": {
               "properties": {
                 "restaurant_customer_review_details": {
                   "type": "nested",
                   "properties": {
                     "customer_id": {
                       "type": "keyword"
                     },
                     "customer_review": {
                       "type": "text"
                     },
                     "customer_score": {
                       "type": "double"
                     },
                     "customer_username": {
                       "type": "text"
                     }
                   }
                 }
               }
             }
           }
         }

```

Sample nested object (that can index without error)

```
     {
       "restaurant_customer_review_details": [
         {
           "customer_id": "CR101",
           "customer_username": "Luke Skywalker",
           "customer_review": "This is the greatest restaurant ever!",
           "customer_score": 4
         },
         {
           "customer_id": "CR102",
           "customer_username": "Leia Organa",
           "customer_review": "quite good",
           "customer_score": 4
         },
         {
           "customer_id": "CR103",
           "customer_username": "Han Solo",
           "customer_review": "really good",
           "customer_score": 5
         }
       ]
     }

```

> ```
> Here's restaurant_payment mappings (the problem index)
> {
> "mappings": {
> "restaurant_payment": {
> "properties": {
> "restaurant_credit_card_details": {
> "type": "nested",
> "properties": {
> "credit_card_bank": {
> "type": "keyword"
> },
> "credit_card_condition": {
> "type": "text"
> },
> "credit_card_privillage": {
> "type": "text"
> },
> "credit_card_type": {
> "type": "keyword"
> }
> }
> }
> }
> }
> }
> }
> 
> ```

Sample nested object (that always return error) it is contain in file "my\_payment"

> ```
> {
> "restaurant_credit_card_details": [
> {
> "credit_card_type": "VISA",
> "credit_card_bank": "ABC",
> "credit_card_condition": "Charge 3%",
> "credit_card_privillage": "none"
> },
> {
> "credit_card_type": "VISA",
> "credit_card_bank": "DFG",
> "credit_card_condition": "Charge 3%",
> "credit_card_privillage": "get 100 point"
> }
> ]
> }
> 
> ```

Here's the result when i indexed by cURL

```
 curl -s -H "Content-Type: application/x-ndjson" -XPOST "http://localhost:9200/restaurant_payment/_bulk" --data-binary @D:\my_payment.json`
             {
               "took": 7,
               "errors": true,
               "items": [
                 {
                   "index": {
                     "_index": "restaurant_payment",
                     "_type": "payment",
                     "_id": "R001",
                     "status": 400,
                     "error": {
                       "type": "illegal_argument_exception",
                       "reason": "object mapping [restaurant_credit_card_details] can't be changed from nested to non-nested"
                     }
                   }
                 }
               ]
             }

```

But when i indexed restaurant\_payment by Kibana , It can index to server without error.

Now i confuse what's the problem, Is this a bug of cURL or my nested object structure are wrong.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 19, 2018, 7:08am UTC](https://discuss.elastic.co/t/problem-when-indexing-nested-object-elasticsearch-5-6/116177/2 "2018-01-19T07:08:03Z")

</div>

Please format your code using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

What does `my_payment.json` contains?

---

<div class="post-metadata">

**Author:** ![Phongsatorn.P](https://avatars.discourse-cdn.com/v4/letter/p/7cd45c/32.png) [@Phongsatorn.P](https://discuss.elastic.co/u/Phongsatorn.P)\
**Post date:** [January 19, 2018, 7:18am UTC](https://discuss.elastic.co/t/problem-when-indexing-nested-object-elasticsearch-5-6/116177/3 "2018-01-19T07:18:35Z")

</div>

Oh I'm so sorry for forgot to mention about my\_payment file but now I edited.

my\_payment file contained

```
{
  "restaurant_credit_card_details": [
    {
      "credit_card_type": "VISA",
      "credit_card_bank": "ABC",
      "credit_card_condition": "Charge 3%",
      "credit_card_privillage": "none"
    },
    {
      "credit_card_type": "VISA",
      "credit_card_bank": "DFG",
      "credit_card_condition": "Charge 3%",
      "credit_card_privillage": "get 100 point"
    }
  ]
}
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 19, 2018, 7:42am UTC](https://discuss.elastic.co/t/problem-when-indexing-nested-object-elasticsearch-5-6/116177/4 "2018-01-19T07:42:15Z")

</div>

Could edit again your initial post? It contains citation characters (`>`) and can not be used to reproduce your issue. Thanks.

---

<div class="post-metadata">

**Author:** ![Phongsatorn.P](https://avatars.discourse-cdn.com/v4/letter/p/7cd45c/32.png) [@Phongsatorn.P](https://discuss.elastic.co/u/Phongsatorn.P)\
**Post date:** [January 19, 2018, 8:02am UTC](https://discuss.elastic.co/t/problem-when-indexing-nested-object-elasticsearch-5-6/116177/5 "2018-01-19T08:02:06Z")

</div>

I already edit post. Thank you for your advice.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 19, 2018, 9:36am UTC](https://discuss.elastic.co/t/problem-when-indexing-nested-object-elasticsearch-5-6/116177/6 "2018-01-19T09:36:14Z")

</div>

I tried this:

```auto
DELETE test
PUT test
{
  "mappings": {
    "doc": {
      "properties": {
        "restaurant_credit_card_details": {
          "type": "nested",
          "properties": {
            "credit_card_bank": {
              "type": "keyword"
            },
            "credit_card_condition": {
              "type": "text"
            },
            "credit_card_privillage": {
              "type": "text"
            },
            "credit_card_type": {
              "type": "keyword"
            }
          }
        }
      }
    }
  }
}
PUT test/doc/1
{
  "restaurant_credit_card_details": [
    {
      "credit_card_type": "VISA",
      "credit_card_bank": "ABC",
      "credit_card_condition": "Charge 3%",
      "credit_card_privillage": "none"
    },
    {
      "credit_card_type": "VISA",
      "credit_card_bank": "DFG",
      "credit_card_condition": "Charge 3%",
      "credit_card_privillage": "get 100 point"
    }
  ]
}

```

This works very well.

---

<div class="post-metadata">

**Author:** ![Phongsatorn.P](https://avatars.discourse-cdn.com/v4/letter/p/7cd45c/32.png) [@Phongsatorn.P](https://discuss.elastic.co/u/Phongsatorn.P)\
**Post date:** [January 22, 2018, 1:50am UTC](https://discuss.elastic.co/t/problem-when-indexing-nested-object-elasticsearch-5-6/116177/7 "2018-01-22T01:50:03Z")

</div>

Thank you , your code totally works.

But when i added another field to mappings and index new data (named my\_payment\_final) , same problem occurs again.

Index method (cURL)

```
{
  "took": 17,
  "errors": true,
  "items": [
    {
      "index": {
        "_index": "my_payment_final",
        "_type": " restaurant_payment",
        "_id": "R001",
        "status": 400,
        "error": {
          "type": "illegal_argument_exception",
          "reason": "object mapping [restaurant_debit_card_details] can't be changed from nested to non-nested"
        }
      }
    }

```

Here's my new mappings

PUT /my\_payment\_final

```
{
  "mappings": {
    "restaurant_payment": {
      "properties": {
        "restaurant_id": {
          "type": "keyword"
        },
        "restaurant_name": {
          "type": "text"
        },
        "restaurant_payment_tag": {
          "type": "keyword"
        },
        "restaurant_rabbit_payment": {
          "properties": {
            "accept_rabbit": {
              "type": "keyword"
            },
            "rabbit_privillage": {
              "type": "text"
            }
          }
        },
        "restaurant_app_payment_details": {
          "type": "nested",
          "properties": {
            "app_name": {
              "type": "text"
            },
            "app_privillage": {
              "type": "text"
            }
          }
        },
        "restaurant_qr_payment_details": {
          "type": "nested",
          "properties": {
            "qr_app_name": {
              "type": "text"
            },
            "qr_app_privillage": {
              "type": "text"
            }
          }
        },
        "restaurant_credit_card_details": {
          "type": "nested",
          "properties": {
            "credit_card_bank": {
              "type": "keyword"
            },
            "credit_card_condition": {
              "type": "text"
            },
            "credit_card_privillage": {
              "type": "text"
            },
            "credit_card_type": {
              "type": "keyword"
            }
          }
        },
        "restaurant_debit_card_details": {
          "type": "nested",
          "properties": {
            "debit_card_bank": {
              "type": "keyword"
            },
            "debit_card_condition": {
              "type": "text"
            },
            "debit_card_privillage": {
              "type": "text"
            },
            "debit_card_type": {
              "type": "keyword"
            }
          }
        }
      }
    }
  }
}

```

Here's my new file "my\_payment\_final.json" that i used bulk api by cURL

```
{
  "restaurant_id": "R001",
  "restaurant_name": "Vanilla",
  "restaurant_payment_tag": [
    "rabbit",
    "rabbitlinepay",
    "qr",
    "creditcard",
    "debitcard"
  ],
  "restaurant_rabbit_payment": {
    "accept_rabbit": "yes",
    "rabbit_privillage": "discount 10% when paid by rabbit"
  },
  "restaurant_app_payment_details": [
    {
      "app_name": "spay",
      "app_privillage": "discount 10% when paid by spay"
    },
    {
      "app_name": "apay",
      "app_privillage": "none"
    }
  ],
  "restaurant_qr_payment_details": [
    {
      "qr_app_name": "B-Bank",
      "qr_app_privillage": "Get bonus point"
    },
    {
      "qr_app_name": "B-banking",
      "qr_app_privillage": "discount 10% "
    }
  ],
  "restaurant_credit_card_details": [
    {
      "credit_card_type": "VISA",
      "credit_card_bank": "SBC",
      "credit_card_condition": "Charge 3%",
      "credit_card_privillage": "none"
    },
    {
      "credit_card_type": "VISA",
      "credit_card_bank": "B-Bank",
      "credit_card_condition": "Charge 3%",
      "credit_card_privillage": "get 100 point"
    },
    {
      "credit_card_type": "Mastercard",
      "credit_card_bank": "SBC",
      "credit_card_condition": "Charge 3%",
      "credit_card_privillage": "none"
    },
    {
      "credit_card_type": "Unionpay",
      "credit_card_bank": "BB Bank",
      "credit_card_condition": "none",
      "credit_card_privillage": "none"
    }
  ],
  "restaurant_debit_card_details": [
    {
      "debit_card_type": "VISA",
      "debit_card_bank": "SBC",
      "debit_card_condition": "none",
      "debit_card_privillage": "none"
    },
    {
      "debit_card_type": "VISA",
      "debit_card_bank": "B-Bank",
      "debit_card_condition": "none",
      "debit_card_privillage": "none"
    },
    {
      "debit_card_type": "Mastercard",
      "debit_card_bank": "SBC",
      "debit_card_condition": "none",
      "debit_card_privillage": "none"
    },
    {
      "debit_card_type": "Unionpay",
      "debit_card_bank": "BB-Bank",
      "debit_card_condition": "none",
      "debit_card_privillage": "none"
    }
  ]
}
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 22, 2018, 10:01am UTC](https://discuss.elastic.co/t/problem-when-indexing-nested-object-elasticsearch-5-6/116177/9 "2018-01-22T10:01:02Z")

</div>

I tried this:

```auto
DELETE test
PUT test
{
  "mappings": {
    "doc": {
      "properties": {
        "restaurant_id": {
          "type": "keyword"
        },
        "restaurant_name": {
          "type": "text"
        },
        "restaurant_payment_tag": {
          "type": "keyword"
        },
        "restaurant_rabbit_payment": {
          "properties": {
            "accept_rabbit": {
              "type": "keyword"
            },
            "rabbit_privillage": {
              "type": "text"
            }
          }
        },
        "restaurant_app_payment_details": {
          "type": "nested",
          "properties": {
            "app_name": {
              "type": "text"
            },
            "app_privillage": {
              "type": "text"
            }
          }
        },
        "restaurant_qr_payment_details": {
          "type": "nested",
          "properties": {
            "qr_app_name": {
              "type": "text"
            },
            "qr_app_privillage": {
              "type": "text"
            }
          }
        },
        "restaurant_credit_card_details": {
          "type": "nested",
          "properties": {
            "credit_card_bank": {
              "type": "keyword"
            },
            "credit_card_condition": {
              "type": "text"
            },
            "credit_card_privillage": {
              "type": "text"
            },
            "credit_card_type": {
              "type": "keyword"
            }
          }
        },
        "restaurant_debit_card_details": {
          "type": "nested",
          "properties": {
            "debit_card_bank": {
              "type": "keyword"
            },
            "debit_card_condition": {
              "type": "text"
            },
            "debit_card_privillage": {
              "type": "text"
            },
            "debit_card_type": {
              "type": "keyword"
            }
          }
        }
      }
    }
  }
}
PUT test/doc/1
{
  "restaurant_id": "R001",
  "restaurant_name": "Vanilla",
  "restaurant_payment_tag": [
    "rabbit",
    "rabbitlinepay",
    "qr",
    "creditcard",
    "debitcard"
  ],
  "restaurant_rabbit_payment": {
    "accept_rabbit": "yes",
    "rabbit_privillage": "discount 10% when paid by rabbit"
  },
  "restaurant_app_payment_details": [
    {
      "app_name": "spay",
      "app_privillage": "discount 10% when paid by spay"
    },
    {
      "app_name": "apay",
      "app_privillage": "none"
    }
  ],
  "restaurant_qr_payment_details": [
    {
      "qr_app_name": "B-Bank",
      "qr_app_privillage": "Get bonus point"
    },
    {
      "qr_app_name": "B-banking",
      "qr_app_privillage": "discount 10% "
    }
  ],
  "restaurant_credit_card_details": [
    {
      "credit_card_type": "VISA",
      "credit_card_bank": "SBC",
      "credit_card_condition": "Charge 3%",
      "credit_card_privillage": "none"
    },
    {
      "credit_card_type": "VISA",
      "credit_card_bank": "B-Bank",
      "credit_card_condition": "Charge 3%",
      "credit_card_privillage": "get 100 point"
    },
    {
      "credit_card_type": "Mastercard",
      "credit_card_bank": "SBC",
      "credit_card_condition": "Charge 3%",
      "credit_card_privillage": "none"
    },
    {
      "credit_card_type": "Unionpay",
      "credit_card_bank": "BB Bank",
      "credit_card_condition": "none",
      "credit_card_privillage": "none"
    }
  ],
  "restaurant_debit_card_details": [
    {
      "debit_card_type": "VISA",
      "debit_card_bank": "SBC",
      "debit_card_condition": "none",
      "debit_card_privillage": "none"
    },
    {
      "debit_card_type": "VISA",
      "debit_card_bank": "B-Bank",
      "debit_card_condition": "none",
      "debit_card_privillage": "none"
    },
    {
      "debit_card_type": "Mastercard",
      "debit_card_bank": "SBC",
      "debit_card_condition": "none",
      "debit_card_privillage": "none"
    },
    {
      "debit_card_type": "Unionpay",
      "debit_card_bank": "BB-Bank",
      "debit_card_condition": "none",
      "debit_card_privillage": "none"
    }
  ]
}

```

It gives:

```auto
{
  "_index": "test",
  "_type": "doc",
  "_id": "1",
  "_version": 1,
  "result": "created",
  "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
  },
  "_seq_no": 0,
  "_primary_term": 1
}

```

There is probably something you don't tell.  
Anyway, if you can reproduce it, please provide a full script as I just gave again as it's easier to reproduce by just copying and pasting in Kibana dev console, then executing.

---

<div class="post-metadata">

**Author:** ![Phongsatorn.P](https://avatars.discourse-cdn.com/v4/letter/p/7cd45c/32.png) [@Phongsatorn.P](https://discuss.elastic.co/u/Phongsatorn.P)\
**Post date:** [January 22, 2018, 10:10am UTC](https://discuss.elastic.co/t/problem-when-indexing-nested-object-elasticsearch-5-6/116177/10 "2018-01-22T10:10:34Z")

</div>

May I asked you something?  
What's your index method (cURL or Kibana)?

This problem occured only when I used bulk index by cURL , It not happended when I index by Kibana dev console. Could it be possibly bug in cURL?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 22, 2018, 10:44am UTC](https://discuss.elastic.co/t/problem-when-indexing-nested-object-elasticsearch-5-6/116177/11 "2018-01-22T10:44:18Z")

</div>

Misuse of bulk API IMO. You are probably missing the header or you have line returns in your doc line.

For a single doc, don't use \_bulk

---

<div class="post-metadata">

**Author:** ![Phongsatorn.P](https://avatars.discourse-cdn.com/v4/letter/p/7cd45c/32.png) [@Phongsatorn.P](https://discuss.elastic.co/u/Phongsatorn.P)\
**Post date:** [January 23, 2018, 3:37am UTC](https://discuss.elastic.co/t/problem-when-indexing-nested-object-elasticsearch-5-6/116177/12 "2018-01-23T03:37:46Z")

</div>

Sorry for typed not clear.

Actually , In "my\_payment\_final.json" included 3 documents (it will be increase later) but in previous reply I cut 2 last document off due to reply's limitation that's why I use bulk api by cURL. Here's my\_payment\_final.json contains

```
  {
  "restaurant_id": "R001",
  "restaurant_name": "Vanilla",
  "restaurant_payment_tag": [
    "rabbit",
    "rabbitlinepay",
    "qr",
    "creditcard",
    "debitcard"
  ],
  "restaurant_rabbit_payment": {
    "accept_rabbit": "yes",
    "rabbit_privillage": "discount 10% when paid by rabbit"
  },
  "restaurant_app_payment_details": [
    {
      "app_name": "spay",
      "app_privillage": "discount 10% when paid by spay"
    },
    {
      "app_name": "apay",
      "app_privillage": "none"
    }
  ],
  "restaurant_qr_payment_details": [
    {
      "qr_app_name": "B-Bank",
      "qr_app_privillage": "Get bonus point"
    },
    {
      "qr_app_name": "B-banking",
      "qr_app_privillage": "discount 10% "
    }
  ],
  "restaurant_credit_card_details": [
    {
      "credit_card_type": "VISA",
      "credit_card_bank": "SBC",
      "credit_card_condition": "Charge 3%",
      "credit_card_privillage": "none"
    },
    {
      "credit_card_type": "VISA",
      "credit_card_bank": "B-Bank",
      "credit_card_condition": "Charge 3%",
      "credit_card_privillage": "get 100 point"
    },
    {
      "credit_card_type": "Mastercard",
      "credit_card_bank": "SBC",
      "credit_card_condition": "Charge 3%",
      "credit_card_privillage": "none"
    },
    {
      "credit_card_type": "Unionpay",
      "credit_card_bank": "BB Bank",
      "credit_card_condition": "none",
      "credit_card_privillage": "none"
    }
  ],
  "restaurant_debit_card_details": [
    {
      "debit_card_type": "VISA",
      "debit_card_bank": "SBC",
      "debit_card_condition": "none",
      "debit_card_privillage": "none"
    },
    {
      "debit_card_type": "VISA",
      "debit_card_bank": "B-Bank",
      "debit_card_condition": "none",
      "debit_card_privillage": "none"
    },
    {
      "debit_card_type": "Mastercard",
      "debit_card_bank": "SBC",
      "debit_card_condition": "none",
      "debit_card_privillage": "none"
    },
    {
      "debit_card_type": "Unionpay",
      "debit_card_bank": "BB-Bank",
      "debit_card_condition": "none",
      "debit_card_privillage": "none"
    }
  ]
}

{
  "restaurant_id": "R002",
  "restaurant_name": "Ros",
  "restaurant_payment_tag": [
    "rabbit",
    "rabbitlinepay",
    "qr",
    "creditcard",
    "debitcard"
  ],
  "restaurant_rabbit_payment": {
    "accept_rabbit": "yes",
    "rabbit_privillage": "discount 10% when paid by rabbit"
  },
  "restaurant_app_payment_details": [
    {
      "app_name": "spay",
      "app_privillage": "discount 10% when paid by spay"
    },
    {
      "app_name": "apay",
      "app_privillage": "none"
    }
  ],
  "restaurant_qr_payment_details": [
    {
      "qr_app_name": "B-Bank",
      "qr_app_privillage": "Get bonus point"
    },
    {
      "qr_app_name": "B-banking",
      "qr_app_privillage": "discount 10% "
    }
  ],
  "restaurant_credit_card_details": [
    {
      "credit_card_type": "VISA",
      "credit_card_bank": "SBC",
      "credit_card_condition": "Charge 3%",
      "credit_card_privillage": "none"
    },
    {
      "credit_card_type": "VISA",
      "credit_card_bank": "B-Bank",
      "credit_card_condition": "Charge 3%",
      "credit_card_privillage": "get 100 point"
    }
  ],
  "restaurant_debit_card_details": [
    {
      "debit_card_type": "VISA",
      "debit_card_bank": "SBC",
      "debit_card_condition": "none",
      "debit_card_privillage": "none"
    },
    {
      "debit_card_type": "VISA",
      "debit_card_bank": "B-Bank",
      "debit_card_condition": "none",
      "debit_card_privillage": "none"
    }
  ]
}

{
  "restaurant_id": "R003",
  "restaurant_name": "Nhai",
  "restaurant_payment_tag": [
    "rabbit",
    "rabbitlinepay"
  ],
  "restaurant_rabbit_payment": {
    "accept_rabbit": "yes",
    "rabbit_privillage": "discount 10% when paid by rabbit"
  },
  "restaurant_app_payment_details": [
    {
      "app_name": "none",
      "app_privillage": "none"
    }
  ],
  "restaurant_qr_payment_details": [
    {
      "qr_app_name": "none",
      "qr_app_privillage": "none"
    }
  ],
  "restaurant_credit_card_details": [
    {
      "credit_card_type": "none",
      "credit_card_bank": "none",
      "credit_card_condition": "none",
      "credit_card_privillage": "none"
    }
  ],
  "restaurant_debit_card_details": [
    {
      "debit_card_type": "none",
      "debit_card_bank": "none",
      "debit_card_condition": "none",
      "debit_card_privillage": "none"
    }
  ]
}
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 23, 2018, 4:14am UTC](https://discuss.elastic.co/t/problem-when-indexing-nested-object-elasticsearch-5-6/116177/13 "2018-01-23T04:14:53Z")

</div>

This file can not be sent as is.  
You need to either conform to the bulk format or split the file and send one by one each doc.

---

<div class="post-metadata">

**Author:** ![Phongsatorn.P](https://avatars.discourse-cdn.com/v4/letter/p/7cd45c/32.png) [@Phongsatorn.P](https://discuss.elastic.co/u/Phongsatorn.P)\
**Post date:** [January 23, 2018, 4:36am UTC](https://discuss.elastic.co/t/problem-when-indexing-nested-object-elasticsearch-5-6/116177/14 "2018-01-23T04:36:01Z")

</div>

I Index "my\_payment\_final.json" by cURL to index named "my\_payment\_final".

`curl -s -H "Content-Type: application/x-ndjson" -XPOST "http://localhost:9200/my_payment_final/_bulk" --data-binary @D:\my_payment_final.json`

Here's bulk api format

```
{"index":{"_index":"my_payment_final","_type":" restaurant_payment","_id":"R001"}}
{"restaurant_id":"R001","restaurant_name":"Vanilla","restaurant_payment_tag":["rabbit","rabbitlinepay","qr","creditcard","debitcard"],"restaurant_rabbit_payment":{"accept_rabbit":"yes","rabbit_privillage":"discount 10% when paid by rabbit"},"restaurant_app_payment_details":[{"app_name":"spay","app_privillage":"discount 10% when paid by spay"},{"app_name":"apay","app_privillage":"none"}],"restaurant_qr_payment_details":[{"qr_app_name":"B-Bank","qr_app_privillage":"Get bonus point"},{"qr_app_name":"B-banking","qr_app_privillage":"discount 10% "}],"restaurant_credit_card_details":[{"credit_card_type":"VISA","credit_card_bank":"SBC","credit_card_condition":"Charge 3%","credit_card_privillage":"none"},{"credit_card_type":"VISA","credit_card_bank":"B-Bank","credit_card_condition":"Charge 3%","credit_card_privillage":"get 100 point"},{"credit_card_type":"Mastercard","credit_card_bank":"SBC","credit_card_condition":"Charge 3%","credit_card_privillage":"none"},{"credit_card_type":"Unionpay","credit_card_bank":"BB Bank","credit_card_condition":"none","credit_card_privillage":"none"}],"restaurant_debit_card_details":[{"debit_card_type":"VISA","debit_card_bank":"SBC","debit_card_condition":"none","debit_card_privillage":"none"},{"debit_card_type":"VISA","debit_card_bank":"B-Bank","debit_card_condition":"none","debit_card_privillage":"none"},{"debit_card_type":"Mastercard","debit_card_bank":"SBC","debit_card_condition":"none","debit_card_privillage":"none"},{"debit_card_type":"Unionpay","debit_card_bank":"BB-Bank","debit_card_condition":"none","debit_card_privillage":"none"}]}

{"index":{"_index":"my_payment_final","_type":" restaurant_payment","_id":"R002"}}
{"restaurant_id":"R002","restaurant_name":"Ros","restaurant_payment_tag":["rabbit","rabbitlinepay","qr","creditcard","debitcard"],"restaurant_rabbit_payment":{"accept_rabbit":"yes","rabbit_privillage":"discount 10% when paid by rabbit"},"restaurant_app_payment_details":[{"app_name":"spay","app_privillage":"discount 10% when paid by spay"},{"app_name":"apay","app_privillage":"none"}],"restaurant_qr_payment_details":[{"qr_app_name":"B-Bank","qr_app_privillage":"Get bonus point"},{"qr_app_name":"B-banking","qr_app_privillage":"discount 10% "}],"restaurant_credit_card_details":[{"credit_card_type":"VISA","credit_card_bank":"SBC","credit_card_condition":"Charge 3%","credit_card_privillage":"none"},{"credit_card_type":"VISA","credit_card_bank":"B-Bank","credit_card_condition":"Charge 3%","credit_card_privillage":"get 100 point"}],"restaurant_debit_card_details":[{"debit_card_type":"VISA","debit_card_bank":"SBC","debit_card_condition":"none","debit_card_privillage":"none"},{"debit_card_type":"VISA","debit_card_bank":"B-Bank","debit_card_condition":"none","debit_card_privillage":"none"}]}

{"index":{"_index":"my_payment_final","_type":" restaurant_payment","_id":"R003"}}
{"restaurant_id":"R003","restaurant_name":"Nhai","restaurant_payment_tag":["rabbit","rabbitlinepay"],"restaurant_rabbit_payment":{"accept_rabbit":"yes","rabbit_privillage":"discount 10% when paid by rabbit"},"restaurant_app_payment_details":[{"app_name":"none","app_privillage":"none"}],"restaurant_qr_payment_details":[{"qr_app_name":"none","qr_app_privillage":"none"}],"restaurant_credit_card_details":[{"credit_card_type":"none","credit_card_bank":"none","credit_card_condition":"none","credit_card_privillage":"none"}],"restaurant_debit_card_details":[{"debit_card_type":"none","debit_card_bank":"none","debit_card_condition":"none","debit_card_privillage":"none"}]}

```

When I index by curl the error always occurred like this (I copy only id":"R001's result , result on id":"R002 and id":"R003 are same as R001)

```
{
  "took": 17,
  "errors": true,
  "items": [
    {
      "index": {
        "_index": "my_payment_final",
        "_type": " restaurant_payment",
        "_id": "R001",
        "status": 400,
        "error": {
          "type": "illegal_argument_exception",
          "reason": "object mapping [restaurant_debit_card_details] can't be changed from nested to non-nested"
        }
      }
    }
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 23, 2018, 7:17am UTC](https://discuss.elastic.co/t/problem-when-indexing-nested-object-elasticsearch-5-6/116177/15 "2018-01-23T07:17:15Z")

</div>

Is there a blank space between your lines?

![image](https://us1.discourse-cdn.com/elastic/original/3X/c/f/cfbea7fff04e9af2394e72c0838fec89c5aa4d3f.jpg)

If so, fix it, it's not compatible with the bulk format.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 23, 2018, 7:20am UTC](https://discuss.elastic.co/t/problem-when-indexing-nested-object-elasticsearch-5-6/116177/16 "2018-01-23T07:20:16Z")

</div>

BTW I ran this and it is working well.

```auto
DELETE test
PUT test
{
  "mappings": {
    "doc": {
      "properties": {
        "restaurant_id": {
          "type": "keyword"
        },
        "restaurant_name": {
          "type": "text"
        },
        "restaurant_payment_tag": {
          "type": "keyword"
        },
        "restaurant_rabbit_payment": {
          "properties": {
            "accept_rabbit": {
              "type": "keyword"
            },
            "rabbit_privillage": {
              "type": "text"
            }
          }
        },
        "restaurant_app_payment_details": {
          "type": "nested",
          "properties": {
            "app_name": {
              "type": "text"
            },
            "app_privillage": {
              "type": "text"
            }
          }
        },
        "restaurant_qr_payment_details": {
          "type": "nested",
          "properties": {
            "qr_app_name": {
              "type": "text"
            },
            "qr_app_privillage": {
              "type": "text"
            }
          }
        },
        "restaurant_credit_card_details": {
          "type": "nested",
          "properties": {
            "credit_card_bank": {
              "type": "keyword"
            },
            "credit_card_condition": {
              "type": "text"
            },
            "credit_card_privillage": {
              "type": "text"
            },
            "credit_card_type": {
              "type": "keyword"
            }
          }
        },
        "restaurant_debit_card_details": {
          "type": "nested",
          "properties": {
            "debit_card_bank": {
              "type": "keyword"
            },
            "debit_card_condition": {
              "type": "text"
            },
            "debit_card_privillage": {
              "type": "text"
            },
            "debit_card_type": {
              "type": "keyword"
            }
          }
        }
      }
    }
  }
}
POST test/_bulk
{"index":{"_index":"test","_type":"doc","_id":"R001"}}
{"restaurant_id":"R001","restaurant_name":"Vanilla","restaurant_payment_tag":["rabbit","rabbitlinepay","qr","creditcard","debitcard"],"restaurant_rabbit_payment":{"accept_rabbit":"yes","rabbit_privillage":"discount 10% when paid by rabbit"},"restaurant_app_payment_details":[{"app_name":"spay","app_privillage":"discount 10% when paid by spay"},{"app_name":"apay","app_privillage":"none"}],"restaurant_qr_payment_details":[{"qr_app_name":"B-Bank","qr_app_privillage":"Get bonus point"},{"qr_app_name":"B-banking","qr_app_privillage":"discount 10% "}],"restaurant_credit_card_details":[{"credit_card_type":"VISA","credit_card_bank":"SBC","credit_card_condition":"Charge 3%","credit_card_privillage":"none"},{"credit_card_type":"VISA","credit_card_bank":"B-Bank","credit_card_condition":"Charge 3%","credit_card_privillage":"get 100 point"},{"credit_card_type":"Mastercard","credit_card_bank":"SBC","credit_card_condition":"Charge 3%","credit_card_privillage":"none"},{"credit_card_type":"Unionpay","credit_card_bank":"BB Bank","credit_card_condition":"none","credit_card_privillage":"none"}],"restaurant_debit_card_details":[{"debit_card_type":"VISA","debit_card_bank":"SBC","debit_card_condition":"none","debit_card_privillage":"none"},{"debit_card_type":"VISA","debit_card_bank":"B-Bank","debit_card_condition":"none","debit_card_privillage":"none"},{"debit_card_type":"Mastercard","debit_card_bank":"SBC","debit_card_condition":"none","debit_card_privillage":"none"},{"debit_card_type":"Unionpay","debit_card_bank":"BB-Bank","debit_card_condition":"none","debit_card_privillage":"none"}]}
{"index":{"_index":"test","_type":"doc","_id":"R002"}}
{"restaurant_id":"R002","restaurant_name":"Ros","restaurant_payment_tag":["rabbit","rabbitlinepay","qr","creditcard","debitcard"],"restaurant_rabbit_payment":{"accept_rabbit":"yes","rabbit_privillage":"discount 10% when paid by rabbit"},"restaurant_app_payment_details":[{"app_name":"spay","app_privillage":"discount 10% when paid by spay"},{"app_name":"apay","app_privillage":"none"}],"restaurant_qr_payment_details":[{"qr_app_name":"B-Bank","qr_app_privillage":"Get bonus point"},{"qr_app_name":"B-banking","qr_app_privillage":"discount 10% "}],"restaurant_credit_card_details":[{"credit_card_type":"VISA","credit_card_bank":"SBC","credit_card_condition":"Charge 3%","credit_card_privillage":"none"},{"credit_card_type":"VISA","credit_card_bank":"B-Bank","credit_card_condition":"Charge 3%","credit_card_privillage":"get 100 point"}],"restaurant_debit_card_details":[{"debit_card_type":"VISA","debit_card_bank":"SBC","debit_card_condition":"none","debit_card_privillage":"none"},{"debit_card_type":"VISA","debit_card_bank":"B-Bank","debit_card_condition":"none","debit_card_privillage":"none"}]}
{"index":{"_index":"test","_type":"doc","_id":"R003"}}
{"restaurant_id":"R003","restaurant_name":"Nhai","restaurant_payment_tag":["rabbit","rabbitlinepay"],"restaurant_rabbit_payment":{"accept_rabbit":"yes","rabbit_privillage":"discount 10% when paid by rabbit"},"restaurant_app_payment_details":[{"app_name":"none","app_privillage":"none"}],"restaurant_qr_payment_details":[{"qr_app_name":"none","qr_app_privillage":"none"}],"restaurant_credit_card_details":[{"credit_card_type":"none","credit_card_bank":"none","credit_card_condition":"none","credit_card_privillage":"none"}],"restaurant_debit_card_details":[{"debit_card_type":"none","debit_card_bank":"none","debit_card_condition":"none","debit_card_privillage":"none"}]}

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 23, 2018, 7:37am UTC](https://discuss.elastic.co/t/problem-when-indexing-nested-object-elasticsearch-5-6/116177/17 "2018-01-23T07:37:02Z")

</div>

Also note that you have a bug here:

```auto
"_type":" restaurant_payment"

```

There is a space before `restaurant_payment`.

---

<div class="post-metadata">

**Author:** ![Phongsatorn.P](https://avatars.discourse-cdn.com/v4/letter/p/7cd45c/32.png) [@Phongsatorn.P](https://discuss.elastic.co/u/Phongsatorn.P)\
**Post date:** [January 23, 2018, 7:42am UTC](https://discuss.elastic.co/t/problem-when-indexing-nested-object-elasticsearch-5-6/116177/18 "2018-01-23T07:42:22Z")

</div>

Oh it's not at all , I've just put blank space between lines for make my data in pretty format.

My indexed file not have blank space.

---

<div class="post-metadata">

**Author:** ![Phongsatorn.P](https://avatars.discourse-cdn.com/v4/letter/p/7cd45c/32.png) [@Phongsatorn.P](https://discuss.elastic.co/u/Phongsatorn.P)\
**Post date:** [January 23, 2018, 7:54am UTC](https://discuss.elastic.co/t/problem-when-indexing-nested-object-elasticsearch-5-6/116177/19 "2018-01-23T07:54:39Z")

</div>

The problem come from blank space issue. now I can index data by cURL without error.

Thank you so much , Mr.dadoonet

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 23, 2018, 7:56am UTC](https://discuss.elastic.co/t/problem-when-indexing-nested-object-elasticsearch-5-6/116177/20 "2018-01-23T07:56:56Z")

</div>

Lesson learned for your next post: please post exactly what you are doing as a full script as I always gave you. That will increase a lot your chances to get a response and have people testing it by just copy and paste your example.

---

<div class="post-metadata">

**Author:** ![Phongsatorn.P](https://avatars.discourse-cdn.com/v4/letter/p/7cd45c/32.png) [@Phongsatorn.P](https://discuss.elastic.co/u/Phongsatorn.P)\
**Post date:** [January 23, 2018, 8:01am UTC](https://discuss.elastic.co/t/problem-when-indexing-nested-object-elasticsearch-5-6/116177/21 "2018-01-23T08:01:48Z")

</div>

Ok , next post i'll fix my mistake.

Thank You for your help Mr.dadoonet.

[Next page](https://discuss.elastic.co/t/problem-when-indexing-nested-object-elasticsearch-5-6/116177.md?page=2)
