# Cant merge the objects while upserting a document in specific index

**URL:** <https://discuss.elastic.co/t/cant-merge-the-objects-while-upserting-a-document-in-specific-index/145057>\
**Category:** Elasticsearch\
**Created:** [August 19, 2018, 2:01pm UTC](https://discuss.elastic.co/t/cant-merge-the-objects-while-upserting-a-document-in-specific-index/145057 "2018-08-19T14:01:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sangeeth\_Kumar](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Sangeeth\_Kumar](https://discuss.elastic.co/u/Sangeeth_Kumar)\
**Post date:** [August 19, 2018, 2:01pm UTC](https://discuss.elastic.co/t/cant-merge-the-objects-while-upserting-a-document-in-specific-index/145057/1 "2018-08-19T14:01:41Z")

</div>

I have index called "channel", first document has attribute "Members" and its type is list.

[{'\_id': 'everyone', 'Name': 'Everyone', 'Type': 'Group', '\_created\_at': datetime.datetime(2018, 8, 2, 10, 36, 3, 369000), '\_created\_by': 'Us\_d7b076f0963f11e8b5060242ac120015'},  
{'Name': 'Prasanna', 'Type': 'User', '\_id': 'Us\_088af4a2965011e8b5060242ac120015', '\_created\_by': {'\_id': 'Us\_796d0ff69a0c11e8a7db0242ac12000a'}, '\_created\_at': datetime.datetime(2018, 8, 13, 11, 58, 4, 863000)}]

I have Members.\_created by will be dict or string. How can i store the data?

Error : "type":"illegal\_argument\_exception","reason":"Can't merge a non object mapping [Members.\_created\_by] with an object mapping [Members.\_created\_by]"

---

<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:** [August 19, 2018, 3:05pm UTC](https://discuss.elastic.co/t/cant-merge-the-objects-while-upserting-a-document-in-specific-index/145057/2 "2018-08-19T15:05:53Z")

</div>

> [@Sangeeth\_Kumar](#):
>
> I have Members.\_created by will be dict or string. How can i store the data?

If you want to index this data, it has to be either one or the other as every field must have a single mapping within an index.

---

<div class="post-metadata">

**Author:** ![Sangeeth\_Kumar](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Sangeeth\_Kumar](https://discuss.elastic.co/u/Sangeeth_Kumar)\
**Post date:** [August 19, 2018, 3:17pm UTC](https://discuss.elastic.co/t/cant-merge-the-objects-while-upserting-a-document-in-specific-index/145057/3 "2018-08-19T15:17:25Z")

</div>

Could you please explain in detail?

---

<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:** [August 19, 2018, 3:19pm UTC](https://discuss.elastic.co/t/cant-merge-the-objects-while-upserting-a-document-in-specific-index/145057/4 "2018-08-19T15:19:04Z")

</div>

Each field, e.g. `_created_by`, must have a single mapping within an index. You can therefore not have a field that can be either a string or an object. The only way you might be able to actually store it I believe is if you make it non-searchable. If you want to be able to search on this field you will therefore need to change the structure of your document.

---

<div class="post-metadata">

**Author:** ![Sangeeth\_Kumar](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Sangeeth\_Kumar](https://discuss.elastic.co/u/Sangeeth_Kumar)\
**Post date:** [August 19, 2018, 3:20pm UTC](https://discuss.elastic.co/t/cant-merge-the-objects-while-upserting-a-document-in-specific-index/145057/5 "2018-08-19T15:20:53Z")

</div>

Is there any link to how to create single mapping for field?

---

<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:** [August 19, 2018, 3:22pm UTC](https://discuss.elastic.co/t/cant-merge-the-objects-while-upserting-a-document-in-specific-index/145057/6 "2018-08-19T15:22:21Z")

</div>

Have a look at [the docs](https://www.elastic.co/guide/en/elasticsearch/reference/6.3/mapping.html). This however requires that you change the document so that `_created_by` always is of one type (string or object).

---

<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:** [September 16, 2018, 3:22pm UTC](https://discuss.elastic.co/t/cant-merge-the-objects-while-upserting-a-document-in-specific-index/145057/7 "2018-09-16T15:22:22Z")

</div>

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