当前位置:   article > 正文

ElasticSearch新增字段_elasticsearch 新增字段

elasticsearch 新增字段

环境: 阿里云ElasticSearch 6.7
需求: 给指定索引增加字段

  1. 创建一个索引
PUT /indexName
{
  "settings": {
    "number_of_shards": 2,
    "number_of_replicas": 1
  },
  "mappings": {
    "_doc": {
      "properties": {
        "id": {
          "type": "long"
        },
        "name": {
          "type": "text"
        },
        "picture_url": {
          "type": "keyword"
        }
      }
    }
  }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

查看创建好的索引mapping,显示如下:

{
  "hello" : {
    "mappings" : {
      "_doc" : {
        "properties" : {
          "id" : {
            "type" : "long"
          },
          "name" : {
            "type" : "text"
          },
          "picture_url" : {
            "type" : "keyword"
          }
        }
      }
    }
  }
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  1. 增加新的字段
PUT /hello/_doc/_mapping
{
  "properties": {
    "extendInfo": {
      "type": "text"
    },
    "stock": {
      "type": "integer"
    }
  }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

再次查看该索引的mapping,发现mapping发生了改变,字段增加上去了。

{
  "hello" : {
    "mappings" : {
      "_doc" : {
        "properties" : {
          "extendInfo" : {
            "type" : "text"
          },
          "id" : {
            "type" : "long"
          },
          "name" : {
            "type" : "text"
          },
          "picture_url" : {
            "type" : "keyword"
          },
          "stock" : {
            "type" : "integer"
          }
        }
      }
    }
  }
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  1. 如果是嵌套节点下面新增字段
PUT hello/_doc/_mapping
{
    "properties": {
        "channelTradeNo": {
            "type": "keyword",
            "norms": false,
            "doc_values": false
        },
        "orderDetails": {
            "type": "nested",
            "properties": {
                "rightsStatus": {
                    "type": "keyword",
                    "norms": false,
                    "doc_values": false
                },
                "rightsCurrTime": {
                    "type": "keyword",
                    "norms": false,
                    "doc_values": false
                },
                "rightsEndTime": {
                    "type": "keyword",
                    "norms": false,
                    "doc_values": false
                }
            }
        }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

结束语:分享是一种乐趣,你知道的越多,你知道的越少。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/代码探险家/article/detail/912744
推荐阅读
相关标签
  

闽ICP备14008679号