avatar
童琦杰
Dec 27, 2021Technology

Elasticsearch API

创建索引

bash
curl --request PUT 'http://localhost:9200/logging'

创建成功响应

json
{"acknowledged":true,"shards_acknowledged":true,"index":"logging"}

删除索引

bash
curl --request DELETE 'http://localhost:9200/logging'

删除成功响应

json
{"acknowledged":true}

设置字段动态映射

bash
curl --request PUT 'http://localhost:9200/logging/_mapping' \
--header 'Content-Type: application/json' \
--data-raw '{
    "dynamic": true
}'

设置成功响应

json
{"acknowledged":true}

创建字段

keyword类型字段

bash
curl --request PUT 'http://localhost:9200/logging/_mapping' \
--header 'Content-Type: application/json' \
--data-raw '{
    "properties": {
        "name": {
            "type": "keyword"
        }
    }
}'

成功响应

json
{"acknowledged":true}

date类型字段

bash
curl --request PUT 'http://localhost:9200/_mapping' \
--header 'Content-Type: application/json' \
--data-raw '{
    "properties": {
        "time": {
            "type": "date",
            "format": "yyyy-MM-dd HH:mm:ss.SSS"
        }
    }
}'
bash
curl --request PUT 'http://localhost:9200/_mapping' \
--header 'Content-Type: application/json' \
--data-raw '{
    "properties": {
        "time": {
            "type": "date",
            "format": "epoch_millis"
        }
    }
}'

float类型字段

bash
curl --request PUT 'http://localhost:9200/_mapping' \
--header 'Content-Type: application/json' \
--data-raw '{
    "properties": {
        "number": {
            "type": "float"
        }
    }
}'
© 2015-2022 tongqijie.com 版权所有沪ICP备17000682号