amazon-web-serviceselasticsearchaws-elasticsearchelasticsearch-mapping

Elasticsearch object mapping for tried to parse field [null] as object, but found a concrete value


How can I change mapping or my input to resolve these error, using elasticsearch on AWS,

Mapping:

    {
        "index_patterns": ["*-students-log"],
        "mappings": {
            "properties": {
                "Data": {
                    "type": "object",
                    "properties": {
                        "PASSED": {
                            "type": "object"
                        }
                    }
                },
                "insertion_timestamp": {
                    "type": "date",
                    "format": "epoch_second"
                }
            }
        }
    }

My data :

    curl -XPOST -H 'Content-Type: application/json' https://******.us-east-1.es.amazonaws.com/index_name/_doc/1 -d '{"Data": {"PASSED": ["Vivek"]},"insertion_timestamp": 1591962493}'

Error I got :

    {"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"object mapping for [Data.PASSED] tried to parse field [null] as object, but found a concrete value"}],"type":"mapper_parsing_exception","reason":"object mapping for [Data.PASSED] tried to parse field [null] as object, but found a concrete value"},"status":400}

What is the missing or wrong piece in the above data? Is there any other datatype I should use for array of string? Any help would be appreciated...


Solution

  • JSON arrays are not considered JSON objects when ingested into Elasticsearch.

    The docs state the following regarding arrays:

    There is no dedicated array datatype. Any field can contain zero or more values by default, however, all values in the array must be of the same datatype.

    So, instead of declaring the whole array as an object, specify the array entries' data type (text) directly:

    PUT abc-students-log
    {
      "mappings": {
        "properties": {
          "Data": {
            "type": "object",
            "properties": {
              "PASSED": {
                "type": "text"   
              }
            }
          },
          "insertion_timestamp": {
            "type": "date",
            "format": "epoch_second"
          }
        }
      }
    }
    
    POST abc-students-log/_doc
    {
      "Data": {
        "PASSED": [
          "Vivek"
        ]
      },
      "insertion_timestamp": 1591962493
    }