ElasticSearch常用命令(一)—— 增删改查命令

1、新增索引

curl -H "Content-Type:application/json;charset=utf-8"  -XPUT 'http://127.0.0.1:9200/test_0527'

2、新增mapping

type为"text"类型的字段:

text:会被分词,然后进行索引,支持模糊查询;不支持聚合(适用于全文搜索)

keyword:不进行分词,直接索引;精确查询;支持聚合(适用于关键词搜索)

curl -H "Content-Type:application/json;charset=utf-8" -XPOST 'http://127.0.0.1:9200/test_0527/doc/_mapping?' -d '{"doc":{"date_detection":false,"properties":{
"name":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},
"mobile_phone":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}
}}}'

3、查询mapping

curl -H "Content-Type:application/json;charset=utf-8" -XGET 'http://127.0.0.1:9200/test_0527/_mapping?pretty'

4、插入文档

curl -H "Content-Type:application/json;charset=utf-8"  -XPOST  'http://127.0.0.1:9200/test_0527/doc?' -d 
'{"name":"张三","mobile_phone":"13522335566"}'

5、查询文档

// 全文查询
curl -H "Content-Type:application/json;charset=utf-8"  -XPOST  'http://127.0.0.1:9200/test_0527/doc/_search?pretty'

// 全文查询返回限定字段
curl -H "Content-Type:application/json;charset=utf-8" -POST 'http://127.0.0.1:9200/test_0527/_search?pretty' -d '{"_source": ["mobile_phone"]}'

// 条件查询,短语精准匹配
curl -H "Content-Type:application/json;charset=utf-8"  -XPOST 'http://127.0.0.1:9200/test_0527/_search?pretty' -d '{"query":{"match_phrase":{"name":"王五"}}}'

// 条件查询,term精准查询
curl -H "Content-Type:application/json;charset=utf-8"  -XPOST  'http://127.0.0.1:9200/test_0527/doc/_search?' -d  '{"query":{"term":{"mobile_phone.keyword":"13522335566"}}}'

// 条件查询,分词匹配
curl -H "Content-Type:application/json;charset=utf-8"  -XPOST 'http://127.0.0.1:9200/test_0527/_search?pretty' -d '{"query":{"match":{"name":"王"}}}'

6、删除文档

curl -H "Content-Type:application/json;charset=utf-8"  -XDELETE  'http://127.0.0.1:9200/test_0527/doc/zo30-GoByqlpGcLNsU9t?'

7、给索引添加别名

curl -H "Content-Type:application/json;charset=utf-8"  -XPOST 'http://127.0.0.1:9200/_aliases' -d '{"actions": [{"add":{"index":"test_0527", "alias":"test"}}]}'

8、查询索引某个字段存在的文档

curl -H "Content-Type:application/json;charset=utf-8"  -XPOST 'http://127.0.0.1:9200/test_0527/_search?pretty' -d '{"query":{"exists" : {"field": "mobile_phone"}}}'

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值