服务器内测试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