Elastic search how to ignore a field in mapping


(Abhijit) #1

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 ?

i have also tried using

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

but to no effect.


(Shane Connelly) #2

Ah. I take it from this example that you're trying to completely discard the "c" field, via "enabled":false

If that's your intent, you've only got 1 small error: you've created the mapping of ftype under the comtest index, but when you add data, you're using /comtest/t/1 which means it's trying to use the mapping t, which doesn't exist.


(Shane Connelly) #3

It's also worth noting that the fundamental reason you need this is hat c->322 field is an array of mixed values, which isn't allowed (https://www.elastic.co/guide/en/elasticsearch/guide/current/complex-core-fields.html#_multivalue_fields). You could switch that to be a nested JSON object instead of a mixed array and that would be fine as well.


(Abhijit) #4

correct ! rookie mistake. thanks for the advice.


(system) #5