# Several types as values to same key

**URL:** <https://discuss.elastic.co/t/several-types-as-values-to-same-key/329194>\
**Category:** Elasticsearch\
**Created:** [April 3, 2023, 9:30am UTC](https://discuss.elastic.co/t/several-types-as-values-to-same-key/329194 "2023-04-03T09:30:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![yael\_shifman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yael_shifman/32/119350_2.png) [@yael\_shifman](https://discuss.elastic.co/u/yael_shifman)\
**Post date:** [April 3, 2023, 9:30am UTC](https://discuss.elastic.co/t/several-types-as-values-to-same-key/329194/1 "2023-04-03T09:30:15Z")

</div>

I have jenkins logs in a json format. (taken with the API)  
the logs have different types of value to the same key:  
'''  
{  
"\_class":"hudson.model.StringParameterValue",  
"name":"MANIFEST\_REVISION",  
"value":"master"  
},  
{  
"\_class":"hudson.model.BooleanParameterValue",  
"name":"CROSS\_CLUSTER",  
"value":false  
},  
'''  
and more. when try to upload them using elastic-python, I got this error:  
BadRequestError(400, 'illegal\_argument\_exception', 'mapper [actions.parameters.value] cannot be changed from type [text] to [boolean]')

I do some digging, but didn't find a solution for that.  
any idea what I can do to upload the json successfully?

thanks!

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [April 4, 2023, 1:56am UTC](https://discuss.elastic.co/t/several-types-as-values-to-same-key/329194/2 "2023-04-04T01:56:19Z")

</div>

> [@yael\_shifman](#):
>
> any idea what I can do to upload the json successfully?

You need to explicitly create a mapping for your index as [explained in the documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/explicit-mapping.html).

The issue here is that you didn't explicitly mapped the fields, so Elasticsearch will try to map it according to the first value it receives for any field, in your case it received a value of _true_ or _false_ and then mapped the field as a `boolean` field, but you have other documents where the value of this field can be something else.

You will need to map the field as `keyword` since it can has values that are not only _true_ or _false_.

---

<div class="post-metadata">

**Author:** ![yael\_shifman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yael_shifman/32/119350_2.png) [@yael\_shifman](https://discuss.elastic.co/u/yael_shifman)\
**Post date:** [April 4, 2023, 4:58am UTC](https://discuss.elastic.co/t/several-types-as-values-to-same-key/329194/3 "2023-04-04T04:58:49Z")

</div>

thanks!  
there is a way to do that not manually? my json file is huge.

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [April 4, 2023, 1:53pm UTC](https://discuss.elastic.co/t/several-types-as-values-to-same-key/329194/4 "2023-04-04T13:53:46Z")

</div>

> [@yael\_shifman](#):
>
> there is a way to do that not manually?

You nee to have the correct mapping for every field, however you can use a dynamic template that will, for example, map every string that elasticsearch receives as a keyword field.

Check this [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-templates.html)

---

<div class="post-metadata">

**Author:** ![yael\_shifman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yael_shifman/32/119350_2.png) [@yael\_shifman](https://discuss.elastic.co/u/yael_shifman)\
**Post date:** [April 5, 2023, 7:34am UTC](https://discuss.elastic.co/t/several-types-as-values-to-same-key/329194/5 "2023-04-05T07:34:56Z")

</div>

thanks! that's very helpful!

---

<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 3, 2023, 7:35am UTC](https://discuss.elastic.co/t/several-types-as-values-to-same-key/329194/6 "2023-05-03T07:35:20Z")

</div>

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