# Updating field that is an empty string

**URL:** <https://discuss.elastic.co/t/updating-field-that-is-an-empty-string/302649>\
**Category:** Elasticsearch\
**Created:** [April 18, 2022, 9:43pm UTC](https://discuss.elastic.co/t/updating-field-that-is-an-empty-string/302649 "2022-04-18T21:43:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![es\_beginner](https://avatars.discourse-cdn.com/v4/letter/e/b9e5f3/32.png) [@es\_beginner](https://discuss.elastic.co/u/es_beginner)\
**Post date:** [April 18, 2022, 9:43pm UTC](https://discuss.elastic.co/t/updating-field-that-is-an-empty-string/302649/1 "2022-04-18T21:43:41Z")

</div>

I currently have an elastic document with a field called `grade`. This field is an empty string. In Kibana, its registered as `grade: (empty)`. Now when I try to update `grade` via:

```auto
 POST index/_update/_id
{
     "doc": {
         "grade" : "A"
      }
}

```

In Kibana, I see `grade: (empty), A` in that particular document. Updating again with a different grade (say B) would return a `grade: (empty), B` so it definitely has something to do with the fact that `grade` for that particular document is empty. How do I fix this most efficiently (i.e. not deleting the entire document and recreating etc.) ?

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [April 18, 2022, 11:49pm UTC](https://discuss.elastic.co/t/updating-field-that-is-an-empty-string/302649/2 "2022-04-18T23:49:44Z")

</div>

Hi @es_beginner

can you show a part of your map?  
Maybe your mapping looks like this:

```auto
{
  "mappings": {
    "properties": {
      "user": {
        "properties": {
          "grade": {
            "type": "text"
          }
        }
      }
    }
  }
}

```

If so, your update should look like this:

```auto
POST index-001/_update/ID
{
  "doc": {
    "user": {
      "grade": "A"
    }
  }
}

```

Knowing how the mapping is going will help to better understand.

---

<div class="post-metadata">

**Author:** ![es\_beginner](https://avatars.discourse-cdn.com/v4/letter/e/b9e5f3/32.png) [@es\_beginner](https://discuss.elastic.co/u/es_beginner)\
**Post date:** [April 19, 2022, 12:11am UTC](https://discuss.elastic.co/t/updating-field-that-is-an-empty-string/302649/3 "2022-04-19T00:11:41Z")

</div>

Hello @RabBit_BR

The mapping looks like this:

```auto
       "mappings": {
          "properties": {     
            "class": {
                   "properties": {
                        "user": {
                            "properties": {
                                "grade": {
                                    "type": "text"
                                }
                            }
                        }
                    }
                }
           }
      }

```

More specifically, In the code I had

```auto
{
  "doc": {
      "class.user.grade": "A" 
    }
}

```

As I mentioned, the field was updated just not in the right way.

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [April 19, 2022, 1:15am UTC](https://discuss.elastic.co/t/updating-field-that-is-an-empty-string/302649/4 "2022-04-19T01:15:37Z")

</div>

Try like that:

```auto
{
  "doc": {
    "class": {
      "user": {
        "grade": "A"
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![es\_beginner](https://avatars.discourse-cdn.com/v4/letter/e/b9e5f3/32.png) [@es\_beginner](https://discuss.elastic.co/u/es_beginner)\
**Post date:** [April 19, 2022, 1:31am UTC](https://discuss.elastic.co/t/updating-field-that-is-an-empty-string/302649/5 "2022-04-19T01:31:36Z")

</div>

@RabBit_BR  
I'll git it a try! I'm curious as to why you think that would make a difference though in the outcome?

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [April 19, 2022, 1:59am UTC](https://discuss.elastic.co/t/updating-field-that-is-an-empty-string/302649/6 "2022-04-19T01:59:49Z")

</div>

Because the way you were doing, created a new field. Make a match and you will see the created field.

```auto
GET index-001/_search
{
  "query": {
    "match": {
       "class.user.grade": "b"
    }
  }
}

```

Results:

```auto
 "hits" : [
      {
        "_index" : "index-001",
        "_type" : "_doc",
        "_id" : "hvuHP4ABGT3bEInW7WTY",
        "_score" : 0.160443,
        "_source" : {
          "class" : {
            "user" : {
              "name" : "a",
              "grade" : "b"
            }
          },
          "class.user.grade" : "A"
        }
      }
    ]

```

---

<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 17, 2022, 2:00am UTC](https://discuss.elastic.co/t/updating-field-that-is-an-empty-string/302649/7 "2022-05-17T02:00:34Z")

</div>

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