ElasticSearch 7 学习(3)映射的介绍与使用

  • type: text 可分词
  • type: keyword 不可分词

创建Mapping PUT请求

  • 请求
localhost:9200/nba/_mapping
  • 请求体
{
    "properties":{    //字段的信息
        "name":{
            "type":"text"
        },
        "team_name":{
            "type":"text"
        },
        "position":{
            "type":"keyword"
        },
        "play_year":{
            "type":"keyword"
        },
        "jerse_no":{
            "type":"keyword"
        }
    }
}
  • 响应
{
    "acknowledged": true
}

查看Mapping信息 GET请求

  • 请求
localhost: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信息 GET请求

  • 请求
localhost:9200/nba,cba/_mapping
  • 响应
{
    "nba": {
        "mappings": {
            "properties": {
                "jerse_no": {
                    "type": "keyword"
                },
                "name": {
                    "type": "text"
                },
                "play_year": {
                    "type": "keyword"
                },
                "position": {
                    "type": "keyword"
                },
                "team_name": {
                    "type": "text"
                }
            }
        }
    },
    "cba": {
        "mappings": {}
    }
}

获取所有Mapping信息第一种方式 GET请求

  • 请求
localhost:9200/_mapping
  • 响应
{
    "nba": {
        "mappings": {
            "properties": {
                "jerse_no": {
                    "type": "keyword"
                },
                "name": {
                    "type": "text"
                },
                "play_year": {
                    "type": "keyword"
                },
                "position": {
                    "type": "keyword"
                },
                "team_name": {
                    "type": "text"
                }
            }
        }
    },
    "cba": {
        "mappings": {}
    }
}

获取所有Mapping信息第二种方式 GET请求

  • 请求
localhost:9200/_all/_mapping
  • 响应
{
    "nba": {
        "mappings": {
            "properties": {
                "jerse_no": {
                    "type": "keyword"
                },
                "name": {
                    "type": "text"
                },
                "play_year": {
                    "type": "keyword"
                },
                "position": {
                    "type": "keyword"
                },
                "team_name": {
                    "type": "text"
                }
            }
        }
    },
    "cba": {
        "mappings": {}
    }
}

增加Mapping字段 POST请求

Mapping 只可增加字段不可修改字段

  • 请求
localhost:9200/nba/_mapping
  • 请求体
{
    "properties":{    
        "name":{
            "type":"text"
        },
        "team_name":{
            "type":"text"
        },
        "position":{
            "type":"keyword"
        },
        "play_year":{
            "type":"keyword"
        },
        "jerse_no":{
            "type":"keyword"
        },
        "country":{  // 增加的国家字段
            "type":"keyword"
        }
    }
}
  • 响应
{
    "acknowledged": true
}
上一篇 ElasticSearch 7 学习(2)索引基本操作
下一篇 ElasticSearch 7 学习(4)文档的增删改查
目录
文章列表
1 Jackson JSON反序列化兼容JSON对象和字符串
Jackson JSON反序列化兼容JSON对象和字符串
2
悲观锁和乐观锁的原理及使用场景
悲观锁和乐观锁的原理及使用场景
3
微信JS-SDK使用步骤
微信JS-SDK使用步骤
4
云服务器挂载数据盘
云服务器挂载数据盘
5
ElasticSearch 7 学习(2)索引基本操作
ElasticSearch 7 学习(2)索引基本操作
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。