从 ES 中删除字段

Remove Fields from ES

我在 ES 上遇到以下错误:

[Elasticsearch exception [type=illegal_argument_exception, reason=Limit of total fields [1000] in index [<index_name>] has been exceeded]]

我不想增加字段大小,因为它会导致内存爆炸。在经历了很多栈溢出的解决方案后,我发现我们需要创建一个备份索引,我是这样创建的:

PUT /<dest_index>

现在,我需要将数据从现有索引复制到上面创建的新索引,同时删除不需要的字段。

所以,我尝试了这个:

创建了删除字段的管道:

PUT _ingest/pipeline/removePropertyMap
{
  "description": "Removes the 'propertyMap' field", 
  "processors": [
    {
      "remove": {
        "field" : "propertyMap"
      }
    }
  ]
}

而且,我正在这样复制数据:

POST _reindex
{
  "source": {
    "index": "<source_index>"
  },
  "dest": {
    "index": "<dest_index>",
    "pipeline": "removePropertyMap"
  }
}

在此之后,我仍然将 propertyMap 视为新索引映射中的一个字段。

我正在通过以下方式检查映射:

GET <dest_index>/_mapping

现在我要删除的字段如下所示:

"project": {
    "type": "text",
    "fields": {
        "keyword": {
            "type": "keyword",
            "ignore_above": 256
        }
    }
},
"properties": {
    "type": "text",
    "fields": {
        "keyword": {
            "type": "keyword",
            "ignore_above": 256
        }
    }
},
"propertyMap": {
    "properties": {
        "90001": {
            "type": "text",
            "fields": {
                "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                }
            }
        },
        {
            ...
        }
    }
}        

这是相同的文档结构:

{
    "<index>": {
        "mappings": {
            "_doc": {
                "properties": {
                    "propertyMap": {
                        "properties": {
                            "field1": {
                                "type": "text",
                                "fields": {
                                    "keyword": {
                                        "type": "keyword",
                                        "ignore_above": 256
                                    }
                                }
                            },
                            "field2": {
                                "properties": {
                                    "anotherField": {
                                        "type": "text",
                                        "fields": {
                                            "keyword": {
                                                "type": "keyword",
                                                "ignore_above": 256
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

属性里面还有大量的其他字段,与字段 1 和字段 2 相同。

我做错了什么?

我对管道不太熟悉,但作为替代解决方案,您是否考虑过相反的方法(指定要保留哪些字段)?

POST _reindex
{
  "source": {
    "index": "<source_index>",
    "_source": ["keep_field_1", "keep_field_2"]
  },
  "dest": {
    "index": "<dest_index>"
  }
}

由于您大约有 1000 个字段限制,因此该列表可能要长得多,但您应该能够相对轻松地从映射中获取它。