curl 操作elasticsearch

服务器内测试es是否开启

curl http://localhost:9200/

返回

{

"name" : "6dc8a4cb3eed",

"cluster_name" : "docker-cluster",

"cluster_uuid" : "s5N-f2KiQ_yrPxcYvqCKLA",

"version" : {

"number" : "7.8.0",

"build_flavor" : "default",

"build_type" : "docker",

"build_hash" : "757314695644ea9a1dc2fecd26d1a43856725e65",

"build_date" : "2020-06-14T19:35:50.234439Z",

"build_snapshot" : false,

"lucene_version" : "8.5.1",

"minimum_wire_compatibility_version" : "6.8.0",

"minimum_index_compatibility_version" : "6.0.0-beta1"

},

"tagline" : "You Know, for Search"

}

代表开启成功

查看索引

curl -XGET http://localhost:9200/_cat/indices?v=

查看集群健康

curl -XGET localhost:9200/_cluster/health?pretty

curl -XGET http://localhost:9200/youtube_user_info_post/_count

查询全部

curl -XPOST http://localhost:9200/user_book/_search -H 'Content-Type: application/json' -d ' { "query": { "match_all": {} } } '

统计件数

track_total_hits: true真实件数

curl -XPOST http://localhost:9200/user_book/_search?pretty -H 'Content-Type:application/json' -d ' { "size": 0, "track_total_hits": true } '

写入数据

curl -XPOST http://localhost:9200/user_book/_doc/1 -H 'Content-Type:application/json' -d ' { "name":"Titanic", "type":"romance", "country":"America", "director":"jackma", "date":"2000-12-19", "sex":"男" } '

curl -XPOST http://localhost:9200/myindex/_search?pretty -H 'Content-Type:application/json' -d ' { "track_total_hits": true, "size": 0, "query": { "match_all": {} } } '

删除索引

curl -XDELETE http://localhost:9200/youtube_user_info_post

使用聚合统计

curl -XPOST http://localhost:9200/myindex/_search?pretty -H 'Content-Type:application/json' -d ' { "size": 0, "aggs": { "total": { "value_count": { "field": "id" } } } } '

创建索引字段类型

curl -XPUT http://localhost:9200/youtube_user_info_post_copy -H 'Content-Type: application/json' -d ' { "mappings": { "properties": { "location": { "type": "keyword" }, "post_id": { "type": "keyword" }, "post_tag_name": { "type": "keyword" }, "post_url": { "type": "keyword" }, "user_id": { "type": "keyword" }, "video_time": { "type": "keyword" } } } } '

查看索引字段类型

curl -XGET http://localhost:9200/user_book/_mapping?pretty

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值