关于elasticsearch:elasticsearch-添加新字段

在应用ES的时候,给原有index的增加、删除、批改等操作都是比拟常见的景象。因而,记录一些罕用的用法对咱们开发效率将有很大晋升。

后面的文章曾经介绍了如何创立ES索引的,本次实例讲持续应用应用datacube_live索引来做演示。

为了不便观看,依然将datacube_live的现有构造展示进去,本次用来演示在datacube_live增加is_del字段,来给es数据做软删除标记,将is_del类型定义为boolean类型。

1.获取datacube_live以后构造体:

GET http://xxxx:9200/datacube_live/_mapping

{
    "datacube_live": {
        "mappings": {
            "properties": {
                "create_at": {
                    "type": "keyword"
                },
                "creator_id": {
                    "type": "keyword"
                },
                "goods_list": {
                    "type": "nested",
                    "properties": {
                        "activity_type": {
                            "type": "keyword"
                        },
                        "area_ids": {
                            "type": "keyword"
                        },
                        "category_id": {
                            "type": "keyword"
                        },
                        "goods_id": {
                            "type": "keyword"
                        },
                        "goods_name": {
                            "type": "text"
                        },
                        "lecture_type": {
                            "type": "keyword"
                        },
                        "sku_code": {
                            "type": "keyword"
                        }
                    }
                },
                "is_callback": {
                    "type": "boolean"
                },
                "is_empty": {
                    "type": "boolean"
                },
                "is_pal_15": {
                    "type": "boolean"
                },
                "live_date": {
                    "type": "keyword"
                },
                "live_start_time": {
                    "type": "keyword"
                },
                "push_type": {
                    "type": "keyword"
                },
                "room_id": {
                    "type": "keyword"
                },
                "room_name": {
                    "type": "text"
                },
                "shop_ids": {
                    "type": "keyword"
                }
            }
        }
    }
}

2.定义is_del类型

在定义is_del类型的时候,须要将其放入properties属性当中去,构造如下所示。

{
    "properties": {
        "is_del": {
            "type": "boolean"
        }
    }
}

3.将定义的is_del字段增加至datacube_live构造体当中去。

调用ES的http://xxxx:9200/datacube_liv…接口,批改构造体。

PUT http://xxxx:9200/datacube_live/_mapping

{
    "properties": {
        "is_del": {
            "type": "boolean"
        }
    }
}

4.验证构造体

GET http://xxxx:9200/datacube_live/_mapping

{
    "datacube_live": {
        "mappings": {
            "properties": {
                "create_at": {
                    "type": "keyword"
                },
                "creator_id": {
                    "type": "keyword"
                },
                "goods_list": {
                    "type": "nested",
                    "properties": {
                        "activity_type": {
                            "type": "keyword"
                        },
                        "area_ids": {
                            "type": "keyword"
                        },
                        "category_id": {
                            "type": "keyword"
                        },
                        "goods_id": {
                            "type": "keyword"
                        },
                        "goods_name": {
                            "type": "text"
                        },
                        "lecture_type": {
                            "type": "keyword"
                        },
                        "sku_code": {
                            "type": "keyword"
                        }
                    }
                },
                "is_callback": {
                    "type": "boolean"
                },
                "is_del": {
                    "type": "boolean"
                },
                "is_empty": {
                    "type": "boolean"
                },
                "is_pal_15": {
                    "type": "boolean"
                },
                "live_date": {
                    "type": "keyword"
                },
                "live_start_time": {
                    "type": "keyword"
                },
                "push_type": {
                    "type": "keyword"
                },
                "room_id": {
                    "type": "keyword"
                },
                "room_name": {
                    "type": "text"
                },
                "shop_ids": {
                    "type": "keyword"
                }
            }
        }
    }
}

原有datacube_live的构造体增加了is_del类型,如下图所示。

到这里只能阐明is_del新增字段增加胜利了,此时依然不能阐明工作就实现了。如果当初就去查问datacube_live数据的话,目前依然没有is_del属性,须要对datacube_live进行数据更新操作,之后才阐明实现整个字段增加。

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理