【问题标题】:Elastic search how to ignore a field in mapping弹性搜索如何忽略映射中的字段
【发布时间】:2015-12-08 04:58:05
【问题描述】:

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

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

但没有效果。

【问题讨论】:

    标签: elasticsearch lucene elasticsearch-indices


    【解决方案1】:

    因为您已经为类型 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为:

      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-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-11
      相关资源
      最近更新 更多