curl action -u user:password host ...
,需要将 user、password 替换为自己实际的用户名和密码,将 host 替换为自己的 IP。curl -XGET http://10.0.17.2:9200若开启了ES集群用户登录认证,请注意输入用户名密码curl -XGET -u user:password http://10.0.17.2:9200
{"name": "15589826570000*****","cluster_name": "es-******","cluster_uuid": "NGIm1M_zRw-L3o_gH****","version": {"number": "6.4.3","build_flavor": "default","build_type": "zip","build_hash": "fe40335","build_date": "2019-05-17T14:22:47.286024Z","build_snapshot": false,"lucene_version": "7.4.0","minimum_wire_compatibility_version": "5.6.0","minimum_index_compatibility_version": "5.0.0"},"tagline": "You Know, for Search"}
curl -XPUT http://10.0.0.2:9200/china/city/beijing -H 'Content-Type: application/json' -d'{"name":"北京市","province":"北京市","lat":39.9031324643,"lon":116.4010433787,"x":6763,"level.range":4,"level.level":1,"level.name":"一线城市","y":6381,"cityNo":1}'
curl -XPUT -u user:password http://10.0.0.2:9200/china/city/beijing -H 'Content-Type: application/json' -d'{"name":"北京市","province":"北京市","lat":39.9031324643,"lon":116.4010433787,"x":6763,"level.range":4,"level.level":1,"level.name":"一线城市","y":6381,"cityNo":1}'
{"_index":"china","_type":"city","_id":"beijing","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"created":true}
curl -XPOST http://10.0.0.2:9200/_bulk -H 'Content-Type: application/json' -d'{ "index" : { "_index": "china", "_type" : "city", "_id" : "beijing" } }{"name":"北京市","province":"北京市","lat":39.9031324643,"lon":116.4010433787,"x":6763,"level.range":4,"level.level":1,"level.name":"一线城市","y":6381,"cityNo":1}{ "index" : { "_index": "china", "_type" : "city", "_id" : "shanghai" } }{"name":"上海市","province":"上海市","lat":31.2319526784,"lon":121.469443249,"x":7779,"level.range":4,"level.level":1,"level.name":"一线城市","y":4409,"cityNo":2}{ "index" : { "_index": "china", "_type" : "city", "_id" : "guangzhou" } }{"name":"广州市","province":"广东省越秀区吉祥路79号","lat":23.1317146641,"lon":113.2595185241,"x":6173,"level.range":4,"level.level":1,"level.name":"一线城市","y":2560,"cityNo":3}{ "index" : { "_index": "china", "_type" : "city", "_id" : "shenzhen" } }{"name":"深圳市","province":"广东省福田区新园路37号","lat":22.5455465546,"lon":114.0527779134,"x":6336,"level.range":4,"level.level":1,"level.name":"一线城市","y":2429,"cityNo":4}{ "index" : { "_index": "china", "_type" : "city", "_id" : "chengdu" } }{"name":"成都市","province":"四川省锦江区红星路4段-88号-附1号","lat":30.6522796787,"lon":104.0725574128,"x":4387,"level.level":2,"level.range":19,"level.name":"新一线城市","y":4304,"cityNo":5}{ "index" : { "_index": "china", "_type" : "city", "_id" : "hangzhou" } }{"name":"杭州市","province":"浙江省拱墅区环城北路316号","lat":30.2753694112,"lon":120.1509063337,"x":7530,"level.level":2,"level.range":19,"level.name":"新一线城市","y":4182,"cityNo":6}'
"took":9,"errors":false,"items":[{"index":{"_index":"china","_type":"city","_id":"beijing","_version":4,"result":"updated","_shards":{"total":2,"successful":2,"failed":0},"created":false,"status":200}},{"index":{"_index":"china","_type":"city","_id":"shanghai","_version":2,"result":"updated","_shards":{"total":2,"successful":2,"failed":0},"created":false,"status":200}},{"index":{"_index":"china","_type":"city","_id":"guangzhou","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"created":true,"status":201}},{"index":{"_index":"china","_type":"city","_id":"shenzhen","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"created":true,"status":201}},{"index":{"_index":"china","_type":"city","_id":"chengdu","_version":2,"result":"updated","_shards":{"total":2,"successful":2,"failed":0},"created":false,"status":200}},{"index":{"_index":"china","_type":"city","_id":"hangzhou","_version":2,"result":"updated","_shards":{"total":2,"successful":2,"failed":0},"created":false,"status":200}}]
beijing
的文档。 响应如下:{"_index":"china","_type":"city","_id":"beijing","_version":2,"result":"updated","_shards":{"total":2,"successful":2,"failed":0},"created":false}
curl -XGET 'http://10.0.0.2:9200/china/city/beijing?pretty' -H 'Content-Type: application/json'
{"_index" : "china","_type" : "city","_id" : "beijing","_version" : 4,"found" : true,"_source" : {"name" : "北京市","province" : "北京市","lat" : 39.9031324643,"lon" : 116.4010433787,"x" : 6763,"level.range" : 4,"level.level" : 1,"level.name" : "一线城市","y" : 6381,"cityNo" : 1}}
curl -XGET 'http://10.0.0.2:9200/china/city/_search?pretty' -H 'Content-Type: application/json'
{"took" : 0,"timed_out" : false,"_shards" : {"total" : 5,"successful" : 5,"skipped" : 0,"failed" : 0},"hits" : {"total" : 6,"max_score" : 1.0,"hits" : [{"_index" : "china","_type" : "city","_id" : "guangzhou","_score" : 1.0,"_source" : {"name" : "广州市","province" : "广东省越秀区吉祥路79号","lat" : 23.1317146641,"lon" : 113.2595185241,"x" : 6173,"level.range" : 4,"level.level" : 1,"level.name" : "一线城市","y" : 2560,"cityNo" : 3}}]},......}
select * from city where level.level=2curl -XGET http://10.0.0.2:9200/china/city/_search?pretty -H 'Content-Type: application/json' -d'{"query" : {"constant_score" : {"filter" : {"term" : {"level.level" : 2}}}}}'
{"took" : 2,"timed_out" : false,"_shards" : {"total" : 5,"successful" : 5,"skipped" : 0,"failed" : 0},"hits" : {"total" : 2,"max_score" : 1.0,"hits" : [{"_index" : "china","_type" : "city","_id" : "chengdu","_score" : 1.0,"_source" : {"name" : "成都市","province" : "四川省锦江区红星路4段-88号-附1号","lat" : 30.6522796787,"lon" : 104.0725574128,"x" : 4387,"level.level" : 2,"level.range" : 19,"level.name" : "新一线城市","y" : 4304,"cityNo" : 5}},{"_index" : "china","_type" : "city","_id" : "hangzhou","_score" : 1.0,"_source" : {"name" : "杭州市","province" : "浙江省拱墅区环城北路316号","lat" : 30.2753694112,"lon" : 120.1509063337,"x" : 7530,"level.level" : 2,"level.range" : 19,"level.name" : "新一线城市","y" : 4182,"cityNo" : 6}}]}}
select level.level, count(1) from city group by level.levelcurl -XGET http://10.0.0.2:9200/china/city/_search?pretty -H 'Content-Type: application/json' -d'{"size" : 0,"aggs" : {"city_level" : {"terms" : {"field" : "level.level"}}}}'
{"took" : 10,"timed_out" : false,"_shards" : {"total" : 5,"successful" : 5,"skipped" : 0,"failed" : 0},"hits" : {"total" : 7,"max_score" : 0.0,"hits" : [ ]},"aggregations" : {"city_level" : {"doc_count_error_upper_bound" : 0,"sum_other_doc_count" : 0,"buckets" : [{"key" : 1,"doc_count" : 4},{"key" : 2,"doc_count" : 3}]}}}
curl -XDELETE 'http://10.0.0.2:9200/china/city/beijing?pretty' -H 'Content-Type: application/json'
{"found" : true,"_index" : "china","_type" : "city","_id" : "beijing","_version" : 5,"result" : "deleted","_shards" : {"total" : 2,"successful" : 2,"failed" : 0}}
curl -XDELETE 'http://10.0.0.2:9200/china/city?pretty' -H 'Content-Type: application/json'
curl -XDELETE 'http://10.0.0.2:9200/china?pretty' -H 'Content-Type: application/json'
本页内容是否解决了您的问题?