您当前的位置: 首页 >  ar

陈橙橙丶

暂无认证

  • 1浏览

    0关注

    107博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

elasticSearch核心概念的介绍(二):映射的介绍和使用

陈橙橙丶 发布时间:2022-02-18 11:31:15 ,浏览量:1

映射的介绍和使用

在上一章介绍了索引的使用,这一章我们来简单介绍 一下 映射,有兴趣的可以参考一下: elasticSearch核心概念的介绍(一):基本介绍和索引的基本使用

  • 新增

    • 请求
    curl -X PUT "http://172.25.45.150:9200/nba/_mapping" -H 'Content-Type:application/json' -d '
    	{
    		"properties":{
                "name":{
                    "type":"text"
                },
                "team_name":{
                    "type":"text"
                },
                "position":{
                    "type":"keyword"
                },
                "play_year":{
                    "type":"keyword"
                },
                "jerse_no":{
                    "type":"keyword"
                }
            }
    	}
    '
    
    • 响应

      {
          "acknowledged": true
      }
      
  • 获取索引mapping

    • 请求

      curl -X GET "http://172.25.45.150:9200/nba/_mapping"
      
    • 响应

      {
          "nba": {
              "mappings": {
                  "properties": {
                      "jerse_no": {
                          "type": "keyword"
                      },
                      "name": {
                          "type": "text"
                      },
                      "play_year": {
                          "type": "keyword"
                      },
                      "position": {
                          "type": "keyword"
                      },
                      "team_name": {
                          "type": "text"
                      }
                  }
              }
          }
      }
      
  • 获取所有mapping

    • 请求

      curl -X GET "http://172.25.45.150:9200/_mapping"
      
  • 修改mapping

    需要注意的是es规定了我们可以对mapping进行新增字段,但是我们无法进行字段类型的修改。例如把某一个字段的type=text修改成type=keyword,如需要修改,我们只能重新创建索引。

    • 请求

      curl -X POST "http://172.25.45.150:9200/nba/_mapping" -H 'Content-Type:application/json' -d '
      {
      		"properties":{
                  "name":{
                      "type":"text"
                  },
                  "team_name":{
                      "type":"text"
                  },
                  "position":{
                      "type":"keyword"
                  },
                  "play_year":{
                      "type":"keyword"
                  },
                  "jerse_no":{
                      "type":"keyword"
                  },
                  "contry":{
                  	"type":"keyword"
                  }
              }
      	}
      '
      
    • 响应

      {
          "acknowledged": true
      }
      
type的介绍
  • text : 表示字段是使用全文索引,可以进行分词,例如 ”我是一名学生“ 他会被分成 我、是、学生 等。
  • keyword:表示是一个关键字,不会被分词。
关注
打赏
1648473527
查看更多评论
立即登录/注册

微信扫码登录

0.0354s