AbtPst
AbtPst

Reputation: 8008

Elastic search how to ignore a field in mapping

i am trying to create a mapping in elastic search to ignore one of the fields in my incoming data. i am following the documentation here

https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-object-type.html#_enabled_3

looks like the enabled property is exactly what i need , but i do not get the desired results.

Here is my mapping

PUT /comtest
{

      "mappings": {
         "ftype": {

            "properties": {
               "a": {
                  "type": "string"
               },
               "b": {
                  "type": "long"
               },

               "c":
               {
                "type" : "object",
                        "enabled" : false
               },
               "d": {
                  "type": "string"
               },
               "e": {
                  "type": "string"
               },
               "f": {
                  "type": "boolean"
               },
               "g": {
                  "type": "string"
               },
               "h": {
                  "type": "string"
               },
               "i": {
                  "type": "long"
               },
               "j": {
                  "type": "string"
               },
               "k": {
                  "type": "long"
               },
               "l": {
                  "type": "date"
               },
               "m": {
                  "type": "string"
               },
               "n": {
                  "type": "string"
               },
               "o": {
                  "type": "string"
               },
               "p": {
                  "type": "string"
               }
            }
         }
      }

}

Here is my data

put /comtest/t/1
{
    "a": "cdcwc",
    "b": 1,
    "c": {
        "6": 22,

        "322": [
            444,
            "ew",
            "fwefwe."
        ]
    },
    "d": null,
    "e": "svgerbgerb",
    "f": false,
    "g": "rethrt",
    "h": null,
    "i": 55,
    "j": null,
    "k": null,
    "l": null,
    "m": "dasd",
    "n": 88,
    "o": "1",
    "p": "asas"
    }

And I get the following error

{
   "error": "MapperParsingException[failed to parse [FIXMessage.448]]; nested: NumberFormatException[For input string: \"ew\"]; ",
   "status": 400
}

Why wasn’t the field ignored ?

Note:

i have also tried the following properties

"store":false, "include_in_all":false, "index":"no"

but to no effect.

Upvotes: 2

Views: 4731

Answers (1)

Dhawal Kapil
Dhawal Kapil

Reputation: 2757

because you have defined mapping for type ftype and you are indexing a type t.

Either change the type of added document to ftype as :

put /comtest/ftype/1
{
    "a": "cdcwc",
    "b": 1,
    "c": {
        "6": 22,

        "322": [
            444,
            "ew",
            "fwefwe."
        ]
    },
    "d": null,
    "e": "svgerbgerb",
    "f": false,
    "g": "rethrt",
    "h": null,
    "i": 55,
    "j": null,
    "k": null,
    "l": null,
    "m": "dasd",
    "n": 88,
    "o": "1",
    "p": "asas"
    }

or change the type in mapping to t as:

  PUT /comtest
  {

  "mappings": {
     "t": {

        "properties": {
           "a": {
              "type": "string"
           },
           "b": {
              "type": "long"
           },

           "c":
           {
            "type" : "object",
                    "enabled" : false
           },
           "d": {
              "type": "string"
           },
           "e": {
              "type": "string"
           },
           "f": {
              "type": "boolean"
           },
           "g": {
              "type": "string"
           },
           "h": {
              "type": "string"
           },
           "i": {
              "type": "long"
           },
           "j": {
              "type": "string"
           },
           "k": {
              "type": "long"
           },
           "l": {
              "type": "date"
           },
           "m": {
              "type": "string"
           },
           "n": {
              "type": "string"
           },
           "o": {
              "type": "string"
           },
           "p": {
              "type": "string"
           }
        }
     }
  }

  }

Upvotes: 5

Related Questions