弹性搜索如何忽略映射中的字段

时间:2015-09-11 15:12:16

标签: elasticsearch lucene elasticsearch-indices

我正在尝试在弹性搜索中创建一个映射,以忽略我的传入数据中的一个字段。我正在关注此处的文档

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

看起来启用属性正是我需要的,但我没有得到理想的结果。

这是我的映射

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"
               }
            }
         }
      }

}

这是我的数据

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"
    }

我收到以下错误

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

为什么不忽视该字段?

注意:

我也尝试过以下属性

“存储”:假, “include_in_all”:假的, “索引”: “否”

但没有效果。

1 个答案:

答案 0 :(得分:5)

因为您已为类型SELECT col1, col2, col3, NULL AS col4 FROM mytable 定义了映射,并且您正在为类型ftype编制索引。

将添加的文档类型更改为t

ftype

或将映射中的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" } 更改为type

t