# Mapping Json Object and Array under the same field

**URL:** <https://discuss.elastic.co/t/mapping-json-object-and-array-under-the-same-field/294853>\
**Category:** Elasticsearch\
**Created:** [January 19, 2022, 4:25pm UTC](https://discuss.elastic.co/t/mapping-json-object-and-array-under-the-same-field/294853 "2022-01-19T16:25:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Remi\_Czternasty](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/remi_czternasty/32/99210_2.png) [@Remi\_Czternasty](https://discuss.elastic.co/u/Remi_Czternasty)\
**Post date:** [January 19, 2022, 4:25pm UTC](https://discuss.elastic.co/t/mapping-json-object-and-array-under-the-same-field/294853/1 "2022-01-19T16:25:49Z")

</div>

Hello,

I'm trying to ingests logs that are json documents. As I don't know the structure of each possible logs, I'm looking into dynamic templates. And I encounter an issue because I have a case where a field is an object in one case and an array in another case.

Ex:  
doc1

```auto
{
  "inputPayload": [
    {
      "priority": 2,
      "refId": "e9b0cfe9-5426-4082-9b30-ba81c807910f"
    },
    {
      "priority": 2,
      "refId": "76a82805-fdea-4376-b762-f839ad3ec122"
    }
  ]
}

```

doc2

```auto
{
  "inputPayload": [
    "d92bb07c-b6c5-4634-8622-7bed1740be12",
    "d92bb07c-b6c5-4634-8622-7bed1740be13"
  ]
}

```

I don't really need to have doc1 indexed as an structured object. Is there a combination of settings to index those 2 documents under the same index? Or a least a way to index the object as a text.

For now I've tested to:

- use [flattened](https://www.elastic.co/guide/en/elasticsearch/reference/current/flattened.html) type, but flattened type is not compatible with the array
- use [enabled](https://www.elastic.co/guide/en/elasticsearch/reference/current/enabled.html) on the object, but once I've indexed a array document, I get an error on the object document.

Thanks for your help,

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [January 25, 2022, 3:51pm UTC](https://discuss.elastic.co/t/mapping-json-object-and-array-under-the-same-field/294853/2 "2022-01-25T15:51:23Z")

</div>

Regarding `enabled`, what did you try? I tried this and it worked. However this means, that no data is searchable. Is that ok for you or not?

```auto
{
  "mappings": {
    "properties": {
      "inputPayload": {
        "type": "object",
        "enabled": false
      }
    }
  }
}

```

Neither flattened nor nested would solve your use-case, unless you are willing to restructure that JSON data structure.

---

<div class="post-metadata">

**Author:** ![Remi\_Czternasty](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/remi_czternasty/32/99210_2.png) [@Remi\_Czternasty](https://discuss.elastic.co/u/Remi_Czternasty)\
**Post date:** [February 16, 2022, 4:38pm UTC](https://discuss.elastic.co/t/mapping-json-object-and-array-under-the-same-field/294853/3 "2022-02-16T16:38:23Z")

</div>

Thanks, I've tried it and it works!

---

<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:** [March 16, 2022, 4:38pm UTC](https://discuss.elastic.co/t/mapping-json-object-and-array-under-the-same-field/294853/4 "2022-03-16T16:38:29Z")

</div>

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