【es】索引的增删改查

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 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值