日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

分布式是写出来的(三)

發布時間:2023/11/30 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 分布式是写出来的(三) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

添加元數據服務

元數據服務就是對元數據提供存取功能的服務。元數據就是系統定義的基本信息,比如一張相片的名字,版本,拍攝時間,散列值等。客戶端和接口服務之間根據對象的名字來引用一個對象,一個對象可以有多個版本,除了刪除標志外,每個版本指向數據服務的一個實際的數據存儲

ES的基本使用

ES或者任意的一個分布式數據庫都可以作為元數據服務
啟動(windows)elasticsearch-7.6.2-windows-x86_64\elasticsearch-7.6.2\bin\elasticsearch.bat
成功http://192.168.7.6:9200/people

鏈接服務器的golang操作

全文搜索引擎 Elasticsearch 入門教程 作者: 阮一峰
ES官方中文手冊
添加索引

package mainimport ("context""fmt""github.com/olivere/elastic" )func main(){Client, err := elastic.NewClient(elastic.SetURL("http://192.168.7.6:9200"))fmt.Println(Client, err)name := "people2"Client.CreateIndex(name).Do(context.Background()) }

插入和查找

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服務器

$ 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"}

往索引庫中新增數據

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

插入單條數據

curl -XPUT localhost:9200/people/external/1?format=yaml' -d quote> { "name":"paxi"}'

查詢單條數據

curl -XGET localhost:9200/people2/_search?pretty

刪除單條數據

curl -XDELETE localhost:9200/people2/external/3?format=yaml

ES進行更新PUT請求時,會重發數據

第一次PUT

$ curl -X PUT 'localhost:9200/accounts/person/1' -d ' {"user": "張三","title": "工程師","desc": "數據庫管理" }' --------------------------------------------------- {"_index":"accounts","_type":"person","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"created":true }

第二次PUT,更改了數據,banben_version加1

$ curl -X PUT 'localhost:9200/accounts/person/1' -d ' {"user" : "張三","title" : "工程師","desc" : "數據庫管理,軟件開發" }' ---------------------------------------------------- {----"_index":"accounts","_type":"person","_id":"1","_version":2,"result":"updated","_shards":{"total":2,"successful":1,"failed":0},"created":false } 上面代碼中,我們將原始數據從"數據庫管理"改成"數據庫管理,軟件開發"。 返回結果里面,有幾個字段發生了變化。"_version" : 2, "result" : "updated", "created" : false

總結

以上是生活随笔為你收集整理的分布式是写出来的(三)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。