Home > Blockchain >  ELASTIC tried to parse field [null] as object, but found a concrete value
ELASTIC tried to parse field [null] as object, but found a concrete value

Time:08-19

I know it's a common bug, but I tried everything without success.

I'm trying to update or create a document with an object that inside has some json[] and more. Let me show you, and it will be clearer. This is the query:

{
    const { id } = body;
    const res = await axios.post(
      `${process.env.ELASTIC_URL}/${index}/_doc/${id}`,
      body,
    );
    return res;
  } 

and these is the values:

{
  id: "56b49469-be70-49f8-aa8c-2cdbda1b03fe",
  V2PositionId: "985f8987-c600-463a-8e88-ee580da313ca",
  matchingTitle: "Software Developer - Template 2904",
  matchingDescription: "Also known as a Application Developer or Software Architect",
  matchingDepartment: "General",
  matchingEducation: ['Bachelor of Computer Science'],
  deleted: false,
}

My index:

        "matchingEducation" : {
          "properties" : {
            "certificate" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            }

And when I run this, I get the following error: object mapping for [matchingEducation] tried to parse field [null] as an object, but found a concrete value.

CodePudding user response:

You are getting this exception because matchingEducation field is define as object and you are passing text value to field while indexing.

To resolved this issue, You need to pass document like below:

{
  "id": "56b49469-be70-49f8-aa8c-2cdbda1b03fe",
  "V2PositionId": "985f8987-c600-463a-8e88-ee580da313ca",
  "matchingTitle": "Software Developer - Template 2904",
  "matchingDescription": "Also known as a Application Developer or Software Architect",
  "matchingDepartment": "General",
  "matchingEducation": {
    "certificate" : "Bachelor of Computer Science"
  },
  "deleted": false
}

or you need to update your index mapping where matchingEducation as text type.

{
  "mappings": {
    "properties": {
      "matchingEducation": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      }
    }
  }
}
  • Related