# Index Object structure

**URL:** <https://discuss.elastic.co/t/index-object-structure/346156>\
**Category:** Elasticsearch\
**Tags:** docker\
**Created:** [October 31, 2023, 6:07pm UTC](https://discuss.elastic.co/t/index-object-structure/346156 "2023-10-31T18:07:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![volkerfrank](https://avatars.discourse-cdn.com/v4/letter/v/e36b37/32.png) [@volkerfrank](https://discuss.elastic.co/u/volkerfrank)\
**Post date:** [October 31, 2023, 6:07pm UTC](https://discuss.elastic.co/t/index-object-structure/346156/1 "2023-10-31T18:07:10Z")

</div>

Hi,

how can I index a document with this fields to an index?

```auto
..
                    "gitlab": {
                        "path": "/api/v4/jobs/request",
                        "method": "POST",
                        "params": [
                            {
                                "value": "[FILTERED]",
                                "key": "token"
                            },
                            {
                                "value": {
                                    "features": {
                                        "vault_secrets": "[FILTERED]",
                                        "artifacts_exclude": null
                                    },
                                    "shell": "bash",
                                    "executor": "docker",
                                    "name": "gitlab-runner",
                                    "version": "16.3.1",
                                    "config": {
                                        "gpus": ""
                                    },
                                    "platform": "linux",
                                    "revision": "f5dfa4d1",
                                    "architecture": "amd64"
                                },
                                "key": "info"
                            }
                        ],
...

```

When I try to index a document with this part I get the error:

```auto
(status = 400): {
    "type": "document_parsing_exception",
    "reason": "[1:5992] failed to parse field [gitlab.params.value] of type [keyword] in document with id 'E7OZhosB5SWzhhQTYN73'. Preview of field's value: '...,
    "caused_by": {
        "type": "illegal_state_exception",
        "reason": "Can't get text on a START_OBJECT at 1:5258"
    }
}, dropping event!

```

I think the problem is the object structure that is sometimes under gitlab.params.value.  
Any idea to solve this?

---

<div class="post-metadata">

**Author:** ![azizim](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/azizim/32/127005_2.png) [@azizim](https://discuss.elastic.co/u/azizim)\
**Post date:** [November 1, 2023, 12:03am UTC](https://discuss.elastic.co/t/index-object-structure/346156/2 "2023-11-01T00:03:57Z")

</div>

The problem is that elastic is considering gitlab.params.value as keyword.  
You might want to change to an object in your mapping or you might consider using ingest pipeline to deal with cases where the field is a string .

---

<div class="post-metadata">

**Author:** ![volkerfrank](https://avatars.discourse-cdn.com/v4/letter/v/e36b37/32.png) [@volkerfrank](https://discuss.elastic.co/u/volkerfrank)\
**Post date:** [November 2, 2023, 7:37am UTC](https://discuss.elastic.co/t/index-object-structure/346156/3 "2023-11-02T07:37:11Z")

</div>

OK. The problem is that the field value is sometimes a string and sometimes an object.  
When I change it to object in the mapping, then the strings cannot be indexed.  
Any idea how I can handle this in a pipeline?

---

<div class="post-metadata">

**Author:** ![volkerfrank](https://avatars.discourse-cdn.com/v4/letter/v/e36b37/32.png) [@volkerfrank](https://discuss.elastic.co/u/volkerfrank)\
**Post date:** [November 2, 2023, 6:36pm UTC](https://discuss.elastic.co/t/index-object-structure/346156/4 "2023-11-02T18:36:29Z")

</div>

Thanks for the hint.  
I have found the following solution. I convert the Object to String with this processor:

```auto
  {
    "foreach": {
      "field": "gitlab.params",
      "processor": {
        "convert": {
          "field": "_ingest._value.value",
          "type": "string"
        }
      },
      "description": "convert params.value to String"
    }
  }

```

---

<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:** [November 30, 2023, 6:37pm UTC](https://discuss.elastic.co/t/index-object-structure/346156/5 "2023-11-30T18:37:08Z")

</div>

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