Updating field that is an empty string

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:

 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.) ?

Hi @es_beginner

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

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

If so, your update should look like this:

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

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

Hello @RabBit_BR

The mapping looks like this:

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

More specifically, In the code I had

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

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

Try like that:

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

@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?

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

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

Results:

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

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