分布式是写出来的(三)
生活随笔
收集整理的這篇文章主要介紹了
分布式是写出来的(三)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
添加元數(shù)據(jù)服務(wù)
元數(shù)據(jù)服務(wù)就是對元數(shù)據(jù)提供存取功能的服務(wù)。元數(shù)據(jù)就是系統(tǒng)定義的基本信息,比如一張相片的名字,版本,拍攝時間,散列值等。客戶端和接口服務(wù)之間根據(jù)對象的名字來引用一個對象,一個對象可以有多個版本,除了刪除標志外,每個版本指向數(shù)據(jù)服務(wù)的一個實際的數(shù)據(jù)存儲
ES的基本使用
ES或者任意的一個分布式數(shù)據(jù)庫都可以作為元數(shù)據(jù)服務(wù)
啟動(windows)elasticsearch-7.6.2-windows-x86_64\elasticsearch-7.6.2\bin\elasticsearch.bat
成功http://192.168.7.6:9200/people
鏈接服務(wù)器的golang操作
全文搜索引擎 Elasticsearch 入門教程 作者: 阮一峰
ES官方中文手冊
添加索引
插入和查找
func main(){Client, err := elastic.NewClient(elastic.SetURL("http://192.168.7.6:9200"))fmt.Println(Client, err)name := "people2"data := `{"name": "wali","country": "Chian","age": 30,"date": "1987-03-07"}`_, err = Client.Index().Index(name).Type("man1").Id("1").BodyJson(data).Do(context.Background())get, err := Client.Get().Index(name).Type("man1").Id("1").Do(context.Background())fmt.Println(get, err)ES的API訪問(curl)
常用操作
瀏覽ES服務(wù)器
$ curl -XGET http://localhost:9200/ {"name" : "DESKTOP-PVBHUQ5","cluster_name" : "elasticsearch","cluster_uuid" : "79x294HmR3iDFIQ2M3-_Kg","version" : {"number" : "7.6.2","build_flavor" : "default","build_type" : "zip","build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f","build_date" : "2020-03-26T06:34:37.794943Z","build_snapshot" : false,"lucene_version" : "8.4.0","minimum_wire_compatibility_version" : "6.8.0","minimum_index_compatibility_version" : "6.0.0-beta1"},"tagline" : "You Know, for Search" }插入索引
$curl -XPUT http://localhost:9200/people{"acknowledged":true,"shards_acknowledged":true,"index":"people"}往索引庫中新增數(shù)據(jù)
curl http://localhost:9200/people/ -XPOST -d '{"author" : "a", "name":"a"}'查看集群健康狀況
curl -XGET http://localhost:9200/_cluster/health?format=yaml --- cluster_name: "elasticsearch" status: "yellow" timed_out: false number_of_nodes: 1 number_of_data_nodes: 1 active_primary_shards: 3 active_shards: 3 relocating_shards: 0 initializing_shards: 0 unassigned_shards: 3 delayed_unassigned_shards: 0 number_of_pending_tasks: 0 number_of_in_flight_fetch: 0 task_max_waiting_in_queue_millis: 0 active_shards_percent_as_number: 50.0獲取ES所有索引
$~curl -XGET http://localhost:9200/_cat/indices yellow open people2 OIyNXAzwSvCXdRTM1OCcug 1 1 1 0 10.2kb 10.2kb yellow open bigdata_p GlbTA7_xSVK26L_oU_pVKw 1 1 0 0 283b 283b yellow open people AwsSuR6VS_uCfkNvqDxc6Q 1 1 0 0 283b 283b獲取索引字段
C:\Users\HodgeKou> curl -XGET http://localhost:9200/people2/_mapping?format=yaml --- people2:mappings:properties:age:type: "long"country:type: "text"fields:keyword:type: "keyword"ignore_above: 256date:type: "date"name:type: "text"fields:keyword:type: "keyword"ignore_above: 256新建索引
curl -XPUT localhost:9200/people2刪除索引
curl -XDELETE localhost:9200/people?format=yaml插入單條數(shù)據(jù)
curl -XPUT localhost:9200/people/external/1?format=yaml' -d quote> { "name":"paxi"}'查詢單條數(shù)據(jù)
curl -XGET localhost:9200/people2/_search?pretty刪除單條數(shù)據(jù)
curl -XDELETE localhost:9200/people2/external/3?format=yamlES進行更新PUT請求時,會重發(fā)數(shù)據(jù)
第一次PUT
$ curl -X PUT 'localhost:9200/accounts/person/1' -d ' {"user": "張三","title": "工程師","desc": "數(shù)據(jù)庫管理" }' --------------------------------------------------- {"_index":"accounts","_type":"person","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"created":true }第二次PUT,更改了數(shù)據(jù),banben_version加1
$ curl -X PUT 'localhost:9200/accounts/person/1' -d ' {"user" : "張三","title" : "工程師","desc" : "數(shù)據(jù)庫管理,軟件開發(fā)" }' ---------------------------------------------------- {----"_index":"accounts","_type":"person","_id":"1","_version":2,"result":"updated","_shards":{"total":2,"successful":1,"failed":0},"created":false } 上面代碼中,我們將原始數(shù)據(jù)從"數(shù)據(jù)庫管理"改成"數(shù)據(jù)庫管理,軟件開發(fā)"。 返回結(jié)果里面,有幾個字段發(fā)生了變化。"_version" : 2, "result" : "updated", "created" : false總結(jié)
以上是生活随笔為你收集整理的分布式是写出来的(三)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 分布式是写出来的(二)
- 下一篇: 成都大熊猫繁育研究基地学生票查的严不严