2

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

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”:假,“索引”:“否”

但没有效果。

4

1 回答 1

5

因为您已经为 type 定义了映射ftype并且您正在索引 type 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"
    }

或将typein 映射更改t为:

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

  }
于 2015-09-11T17:04:35.693 回答