elasticsearch 索引操作命令

发布时间 2023-12-10 10:04:19作者: king_wq_庆

一、创建索引

PUT /{索引名}
创建一个索引: king_test_person
PUT /king_test_person
{
    "settings": {
        "refresh_interval": "1s",
        "number_of_shards": "3",
        "number_of_replicas": "2"
    },
    "mappings": {
        "properties": {
            "person_id": {
                "type": "long"
            },
            "name": {
                "type": "keyword"
            },
            "name_pinyin": {
                "type": "text",
                "analyzer": "pinyin"
            },
            "sex": {
                "type": "integer"
            },
            "nationality": {
                "type": "keyword"
            },
            "birthday": {
                "type": "date",
                "format": "yyyy-MM-dd"
            }
        }
    }
}
返回结果:

二、查询索引

2.1 查询所有索引

GET /_cat/indices

2.2 查询单个索引

GET /{索引名}
GET /king_test_person
返回结果:

三、删除索引

DELETE /{索引名}
#测试--删除索引
DELETE /king_test_person

 返回结果

四、创建映射

PUT /{索引名}_mapping
#测试--创建mapping
PUT /king_test_person/_mapping
{
    "properties": {
        "person_id": {
            "type": "long"
        },
        "name": {
            "type": "keyword"
        },
        "name_pinyin": {
            "type": "text",
            "analyzer": "pinyin"
        },
        "sex": {
            "type": "integer"
        },
        "nationality": {
            "type": "keyword"
        },
        "birthday": {
            "type": "date",
            "format": "yyyy-MM-dd"
        }
    }
}

返回