1.创建索引结构
curl -u elastic:elastic -k -XDELETE http://192.168.1.800:9200/test-3-2-1
curl -u elastic:elastic -k -XPUT http://192.168.1.800:9200/test-3-2-1 -H 'Content-Type: application/json' -d '
{
"mappings":{
"properties":{
"id":{"type":"integer"},
"sex":{"type":"boolean"},
"name":{
"type":"text",
"fields":{"keyword":{
"type":"keyword",
"ignore_above":256
}
}
},
"born":{
"type":"date",
"format":"yyyy-MM-dd HH:mm:ss"
},
"location":{"type":"geo_point"}
}
}
}'
2.添加数据
curl -u elastic:elastic -k -XPUT http://192.168.1.800:9200/test-3-2-1/_doc/1 -H 'Content-Type: application/json' -d '
{
"born":"2025-01-02 12:09:09",
"id":"1",
"location":{
"lat":41.12,
"lon":-71.32
},
"name":"张三",
"sex":true
}'
3.查看结构
curl -u elastic:elastic -k -XGET http://192.168.1.800:9200/test-3-2-1/_mapping
{
"test-3-2-1":{
"mappings":{
"properties":{
"born":{
"type":"date",
"format":"yyyy-MM-dd HH:mm:ss"
},
"id":{
"type":"integer"
},
"location":{
"type":"geo_point"
},
"name":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
},
"sex":{
"type":"boolean"
}
}
}
}
}
_type: 元数据说明了元数据的类型。
_index: 元数据说明了索引的名称
_id: 元数据是索引的主键。主键相同时覆盖。
_version: 元数据表示文档的版本号。
_source: 元数据保存了文档数据的完整JSON结构。
3.使用update修改数据
--按主键ID修改。
curl -u elastic:elastic -k -XPOST http://192.168.1.800:9200/test-3-2-1/_update/1 -H 'Content-Type: application/json' -d '
{
"doc":{
"sex":false,
"born":"2021-12-12 12:09:01"
}
}'
4.查询
curl -u elastic:elastic -k -XGET http://192.168.1.800:9200/test-3-2-1/_doc/1
{
"_index":"test-3-2-1",
"_type":"_doc",
"_id":"1",
"_version":2,
"_seq_no":1,
"_primary_term":1,
"found":true,
"_source":{
"born":"2021-12-12 12:09:01",
"id":"1",
"location":{
"lat":41.12,
"lon":-71.32
},
"name":"张三",
"sex":false
}
}
5.按主键删除
curl -u elastic:elastic -k -XDELETE http://192.168.1.800:9200/test-3-2-1/_doc/1