Golang操作ES全系列(olivere curl操作es)

Golang操作ES全系列(olivere & curl操作es)

🚀全部代码(欢迎👏🏻star):

  • https://github.com/ziyifast/ziyifast-code_instruction/tree/main/go-demo/go-es

1 olivere

创建client

package mainimport ("crypto/tls""fmt""github.com/olivere/elastic/v7""net""net/http""time"
)var (//host = "http://localhost:9200"host = "http://es.xx.ziyi.com"
)func main() {esClient, err := elastic.NewClient(elastic.SetURL(host),elastic.SetSniff(false),elastic.SetBasicAuth("", ""),elastic.SetHttpClient(&http.Client{Transport: &DecoratedTransport{tp: &http.Transport{Proxy: http.ProxyFromEnvironment,DialContext: (&net.Dialer{Timeout:   30 * time.Second,KeepAlive: 30 * time.Second,}).DialContext,ForceAttemptHTTP2:     true,MaxIdleConns:          100,IdleConnTimeout:       90 * time.Second,TLSHandshakeTimeout:   10 * time.Second,ExpectContinueTimeout: 1 * time.Second,TLSClientConfig: &tls.Config{InsecureSkipVerify: true,},},}}),)if err != nil {panic(err)}fmt.Println(esClient)
}type DecoratedTransport struct {tp http.RoundTripper
}func (d *DecoratedTransport) RoundTrip(request *http.Request) (*http.Response, error) {request.Host = "es.xx.ziyi.com"return d.tp.RoundTrip(request)
}

在这里插入图片描述

检测索引是否存在

func isExistIndex(esClient *elastic.Client) {isExist, err := esClient.IndexExists("test-ziyi-1-100004-100136").Do(context.TODO())if err != nil {panic(err)}if isExist {println("index exists")} else {println("index not exists")}
}

创建索引

func createIndex(esClient *elastic.Client) {type m map[string]interface{}indexMapping := m{"settings": m{"number_of_shards":   5, //分片数"number_of_replicas": 1, //副本数},"mappings": m{"properties": m{ //索引属性值"book_name": m{ //索引属性名"type": "text", //filed类型//"analyzer": "ik_max_word", //使用ik分词器进行分词"index": true,  //当前field可以被用于查询条件"store": false, //是否额外存储},"author": m{"type": "keyword", //作为关键字不分词},"word_count": m{"type": "long",},"on_sale_time": m{"type":   "date","format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis",},"book_desc": m{"type": "text",//"analyzer": "ik_max_word",},},},}result, err := esClient.CreateIndex("test-ziyi-1-100004-100136").BodyJson(indexMapping).Do(context.Background())if err != nil {panic(err)}if result.Acknowledged {println("create index success")} else {println("create index failed")}
}

删除索引

# 除了程序我们也可以先通过curl查看索引是否存在
curl http://localhost:9200/_cat/indices?v | grep ziyi

在这里插入图片描述

func deleteIndex(esClient *elastic.Client) {response, err := esClient.DeleteIndex("test-ziyi-1-100004-100136").Do(context.Background())if err != nil {panic(err)}println(response.Acknowledged)
}

添加记录doc

# _doc/1 # 表明查询id为1的doc文档
# test-ziyi-1-100004-100136指定索引名
curl -X GET "http://localhost:9200/test-ziyi-1-100004-100136/_doc/1?pretty"

在这里插入图片描述

func addDoc(esClient *elastic.Client) {type m map[string]interface{}documentMappings := m{"book_name":    "士兵突击","author":       "兰晓龙","word_count":   100000,"on_sale_time": "2000-01-05","book_desc":    "一个关于部队的...",}//如果不指定id,则es会自动生成一个id(杂乱无序不好维护),response为返回的文档id//response, err := esClient.Index().Index("test-ziyi-1-100004-100136").BodyJson(documentMappings).Do(context.Background())response, err := esClient.Index().Index("test-ziyi-1-100004-100136").Id("1").BodyJson(documentMappings).Do(context.Background()) //指定idif err != nil {panic(err)}println(response.Id)
}

更新doc记录

在这里插入图片描述

func updateDoc(esClient *elastic.Client) {type m map[string]interface{}docMappings := m{"book_name":    "士兵突击","author":       "袁朗","word_count":   100000,"on_sale_time": "2000-01-05","book_desc":    "一个关于部队的...",}//覆盖式修改(response返回doc记录的id)response, err := esClient.Update().Index("test-ziyi-1-100004-100136").Id("1").Doc(docMappings).Do(context.Background())//指定字段修改//response, err := esClient.Update().Index("test-ziyi-1-100004-100136").Id("1").Doc(map[string]interface{}{//	"book_name": "我的团长我的团",//}).Do(context.Background())if err != nil {panic(err)}println(response.Id)
}

删除doc记录

func deleteDoc(esClient *elastic.Client) {//response返回删除的doc Id,如果要删除的doc不存在,则直接返回err not foundresponse, err := esClient.Delete().Index("test-ziyi-1-100004-100136").Id("1").Do(context.Background())if err != nil {panic(err)}println(response.Id)
}

批处理

func sendBulkRequest(esClient *elastic.Client) {bulkRequest := esClient.Bulk()for i := 0; i < 10; i++ {docMappings := map[string]interface{}{"book_name":    fmt.Sprintf("士兵突击-%d", i),"author":       "袁朗","on_sale_time": "2000-01-05","book_desc":    "一个关于部队的...",}bulkRequest = bulkRequest.Add(elastic.NewBulkIndexRequest().Index("test-ziyi-1-100004-100136").Doc(docMappings))}bulkResponse, err := bulkRequest.Do(context.Background())if err != nil {panic(err)}if bulkResponse.Errors {for _, item := range bulkResponse.Items {for _, action := range item {if action.Error != nil {fmt.Printf("Error for item: %s: %s", action.Error.Index, action.Error.Reason)}}}} else {fmt.Println("All bulk requests executed successfully")}
}

普通查询

func simpleSearch(esClient *elastic.Client) {response, err := esClient.Search([]string{"test-ziyi-1-100004-100136"}...).Query(elastic.NewTermQuery("author", "袁朗")).Size(100).Do(context.TODO())if err != nil {panic(err)}fmt.Println(response.Hits.Hits)
}

在这里插入图片描述

searchAfter翻页查询

func searchAfterSearch(esClient *elastic.Client) {var lastHit *elastic.SearchHitfor {q := elastic.NewBoolQuery().Must(elastic.NewTermQuery("book_name", "士"))searchSource := elastic.NewSearchSource().Query(q).Size(2).Sort("_id", false)if lastHit != nil {fmt.Printf("search After %+v\n", lastHit.Sort)searchSource.SearchAfter(lastHit.Sort...)}dsl, err := searchSource.MarshalJSON()if err != nil {panic(err)}fmt.Printf("dsl %s\n", string(dsl))searchResult, err := esClient.Search().Index("test-ziyi-1-100004-100136").SearchSource(searchSource).Do(context.Background())if err != nil {panic(err)}if len(searchResult.Hits.Hits) == 0 {fmt.Println("no more data")break}for _, hit := range searchResult.Hits.Hits {res := make(map[string]interface{})if err = json.Unmarshal(hit.Source, &res); err != nil {panic(err)}fmt.Printf("search %s %s\n", hit.Id, res["author"])}lastHit = searchResult.Hits.Hits[len(searchResult.Hits.Hits)-1]}
}

全部代码

package mainimport ("context""crypto/tls""encoding/json""fmt""github.com/olivere/elastic/v7""net""net/http""time"
)var (host = "http://test.ziyi.com"
)func main() {esClient := CreateEsClient()fmt.Println(esClient)//1. 操作索引//isExistIndex(esClient)//createIndex(esClient)//deleteIndex(esClient)//2. 操作doc文档(记录)//addDoc(esClient)//updateDoc(esClient)//deleteDoc(esClient)//3. 批处理请求//sendBulkRequest(esClient)//4. 查询//simpleSearch(esClient)//searchAfterSearch(esClient)}func searchAfterSearch(esClient *elastic.Client) {var lastHit *elastic.SearchHitfor {q := elastic.NewBoolQuery().Must(elastic.NewTermQuery("book_name", "士"))searchSource := elastic.NewSearchSource().Query(q).Size(2).Sort("_id", false)if lastHit != nil {fmt.Printf("search After %+v\n", lastHit.Sort)searchSource.SearchAfter(lastHit.Sort...)}dsl, err := searchSource.MarshalJSON()if err != nil {panic(err)}fmt.Printf("dsl %s\n", string(dsl))searchResult, err := esClient.Search().Index("test-ziyi-1-100004-100136").SearchSource(searchSource).Do(context.Background())if err != nil {panic(err)}if len(searchResult.Hits.Hits) == 0 {fmt.Println("no more data")break}for _, hit := range searchResult.Hits.Hits {res := make(map[string]interface{})if err = json.Unmarshal(hit.Source, &res); err != nil {panic(err)}fmt.Printf("search %s %s\n", hit.Id, res["author"])}lastHit = searchResult.Hits.Hits[len(searchResult.Hits.Hits)-1]}
}func simpleSearch(esClient *elastic.Client) {response, err := esClient.Search([]string{"test-ziyi-1-100004-100136"}...).Query(elastic.NewTermQuery("author", "袁朗")).Size(100).Do(context.TODO())if err != nil {panic(err)}fmt.Println(response.Hits.Hits)
}func sendBulkRequest(esClient *elastic.Client) {bulkRequest := esClient.Bulk()for i := 0; i < 10; i++ {docMappings := map[string]interface{}{"book_name":    fmt.Sprintf("士兵突击-%d", i),"author":       "aa","on_sale_time": "2000-01-05","book_desc":    "一个关于部队的...",}bulkRequest = bulkRequest.Add(elastic.NewBulkIndexRequest().Index("test-ziyi-1-100004-100136").Doc(docMappings))}bulkResponse, err := bulkRequest.Do(context.Background())if err != nil {panic(err)}if bulkResponse.Errors {for _, item := range bulkResponse.Items {for _, action := range item {if action.Error != nil {fmt.Printf("Error for item: %s: %s", action.Error.Index, action.Error.Reason)}}}} else {fmt.Println("All bulk requests executed successfully")}
}func deleteDoc(esClient *elastic.Client) {//response返回删除的doc Id,如果要删除的doc不存在,则直接返回err not foundresponse, err := esClient.Delete().Index("test-ziyi-1-100004-100136").Id("1").Do(context.Background())if err != nil {panic(err)}println(response.Id)
}func updateDoc(esClient *elastic.Client) {type m map[string]interface{}docMappings := m{"book_name":    "士兵突击","author":       "袁朗","word_count":   100000,"on_sale_time": "2000-01-05","book_desc":    "一个关于部队的...",}//覆盖式修改(response返回doc记录的id)response, err := esClient.Update().Index("test-ziyi-1-100004-100136").Id("1").Doc(docMappings).Do(context.Background())//指定字段修改//response, err := esClient.Update().Index("test-ziyi-1-100004-100136").Id("1").Doc(map[string]interface{}{//	"book_name": "我的团长我的团",//}).Do(context.Background())if err != nil {panic(err)}println(response.Id)
}func addDoc(esClient *elastic.Client) {type m map[string]interface{}documentMappings := m{"book_name":    "士兵突击","author":       "兰晓龙","word_count":   100000,"on_sale_time": "2000-01-05","book_desc":    "一个关于部队的...",}//如果不指定id,则es会自动生成一个id(杂乱无序不好维护),response为返回的文档id//response, err := esClient.Index().Index("test-ziyi-1-100004-100136").BodyJson(documentMappings).Do(context.Background())response, err := esClient.Index().Index("test-ziyi-1-100004-100136").Id("1").BodyJson(documentMappings).Do(context.Background()) //指定idif err != nil {panic(err)}println(response.Id)
}func deleteIndex(esClient *elastic.Client) {response, err := esClient.DeleteIndex("test-ziyi-1-100004-100136").Do(context.Background())if err != nil {panic(err)}println(response.Acknowledged)
}func createIndex(esClient *elastic.Client) {type m map[string]interface{}indexMapping := m{"settings": m{"number_of_shards":   5, //分片数"number_of_replicas": 1, //副本数},"mappings": m{"properties": m{ //索引属性值"book_name": m{ //索引属性名"type": "text", //filed类型//"analyzer": "ik_max_word", //使用ik分词器进行分词"index": true,  //当前field可以被用于查询条件"store": false, //是否额外存储},"author": m{"type": "keyword", //作为关键字不分词},"word_count": m{"type": "long",},"on_sale_time": m{"type":   "date","format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis",},"book_desc": m{"type": "text",//"analyzer": "ik_max_word",},},},}result, err := esClient.CreateIndex("test-ziyi-1-100004-100136").BodyJson(indexMapping).Do(context.Background())if err != nil {panic(err)}if result.Acknowledged {println("create index success")} else {println("create index failed")}
}func isExistIndex(esClient *elastic.Client) {isExist, err := esClient.IndexExists("test-ziyi-1-100004-100136").Do(context.TODO())if err != nil {panic(err)}if isExist {println("index exists")} else {println("index not exists")}
}func CreateEsClient() *elastic.Client {esClient, err := elastic.NewClient(elastic.SetURL(host),elastic.SetSniff(false),elastic.SetBasicAuth("", ""),elastic.SetHttpClient(&http.Client{Transport: &DecoratedTransport{tp: &http.Transport{Proxy: http.ProxyFromEnvironment,DialContext: (&net.Dialer{Timeout:   30 * time.Second,KeepAlive: 30 * time.Second,}).DialContext,ForceAttemptHTTP2:     true,MaxIdleConns:          100,IdleConnTimeout:       90 * time.Second,TLSHandshakeTimeout:   10 * time.Second,ExpectContinueTimeout: 1 * time.Second,TLSClientConfig: &tls.Config{InsecureSkipVerify: true,},},}}),)if err != nil {panic(err)}return esClient
}type DecoratedTransport struct {tp http.RoundTripper
}func (d *DecoratedTransport) RoundTrip(request *http.Request) (*http.Response, error) {request.Host = "test.ziyi.com"return d.tp.RoundTrip(request)
}

2 go-elasticsearch

searchAfter翻页查询

package mainimport ("context""crypto/tls""encoding/json""fmt""github.com/cenkalti/backoff/v4""github.com/elastic/go-elasticsearch/v7""github.com/elastic/go-elasticsearch/v7/estransport""net""net/http""os""strings""time"
)var (url      = []string{"http://test.ziyi.com"}username = ""password = ""sort     = json.RawMessage(`[{"_id":{"order":"desc"}}]`)aggs     = json.RawMessage(`{"size": {"sum": {"field": "size"}},"count":{"value_count": {"field": "_id"}}}`)size     = 2indices  = []string{"test-ziyi-1-100004-100136"}
)func main() {esClient, err := CreateClient(url, username, password)if err != nil {panic(err)}var searchAfter []interface{}for {dsl := Dsl{Sort:        sort,Size:        size,SearchAfter: searchAfter,Query: map[string]interface{}{"bool": map[string]interface{}{"must": map[string]interface{}{"wildcard": map[string]interface{}{"book_name": "士",},//"match_all": map[string]interface{}{},},},},}queryJson, err := json.MarshalIndent(dsl, "", "\t")if err != nil {panic(err)}fmt.Printf("queryJson:%s\n", queryJson)res, err := esClient.Search(esClient.Search.WithContext(context.Background()),esClient.Search.WithIndex(indices...),esClient.Search.WithBody(strings.NewReader(string(queryJson))),esClient.Search.WithTrackTotalHits(false),)if err != nil {panic(err)}var result struct {Hits struct {Hits []struct {Index  string                 `json:"_index"`ID     string                 `json:"_id"`Sort   []interface{}          `json:"sort"`Source map[string]interface{} `json:"_source"`} `json:"hits"`} `json:"hits"`}if err := json.NewDecoder(res.Body).Decode(&result); err != nil {panic(err)}err = res.Body.Close()if err != nil {panic(err)}if len(result.Hits.Hits) > 0 {lastHit := result.Hits.Hits[len(result.Hits.Hits)-1]searchAfter = lastHit.Sort} else {break}for _, h := range result.Hits.Hits {fmt.Printf("=====id:%s book_name:%s\n", h.ID, h.Source["book_name"])}}
}type Dsl struct {Sort        json.RawMessage        `json:"sort"`Size        int                    `json:"size"`SearchAfter []interface{}          `json:"search_after,omitempty"`Query       map[string]interface{} `json:"query"`
}func CreateClient(url []string, username, password string) (*elasticsearch.Client, error) {es, err := elasticsearch.NewClient(genConfig(url, username, password))if err != nil {panic(err)return nil, err}res, err := es.Info()if err != nil {panic(err)return nil, err}defer res.Body.Close()return es, nil}type DecoratedTransport struct {tp http.RoundTripper
}func (d *DecoratedTransport) RoundTrip(request *http.Request) (*http.Response, error) {request.Host = "test.ziyi.com"return d.tp.RoundTrip(request)
}func genConfig(url []string, username, password string) elasticsearch.Config {retryBackoff := backoff.NewExponentialBackOff()cfg := elasticsearch.Config{Addresses:     url,Logger:        &estransport.ColorLogger{Output: os.Stdout},Username:      username,Password:      password,RetryOnStatus: []int{502, 503, 504, 429},RetryBackoff: func(i int) time.Duration {if i == 1 {retryBackoff.Reset()}return retryBackoff.NextBackOff()},MaxRetries: 5,Transport: &DecoratedTransport{tp: &http.Transport{Proxy: http.ProxyFromEnvironment,DialContext: (&net.Dialer{Timeout:   30 * time.Second,KeepAlive: 30 * time.Second,}).DialContext,ForceAttemptHTTP2:     true,MaxIdleConns:          100,IdleConnTimeout:       90 * time.Second,TLSHandshakeTimeout:   10 * time.Second,ExpectContinueTimeout: 1 * time.Second,TLSClientConfig: &tls.Config{InsecureSkipVerify: true,},},},}return cfg
}

3 拓展

es基础概念

索引index(databse)

类型type(table),6.x后弃用

文档doc(row)

属性field(column)

curl操作es

curl localhost:9200/_cluster/health # 查看集群健康状态
curl localhost:9200/_cat/pending_tasks # 查看任务堆积详情
curl localhost:9200/_cluster/state/metadata # 查看集群元数据状态信息 
curl localhost:9200/_cluster/stats # 查看集群指标统计信息
curl localhost:9200/_cluster/allocation/explain # 查看集群分片分配详情
curl localhost:9200/_cluster/allocation/explain #查看集群分片分配详情
curl http://localhost:9200/test-*/_count # 统计文档总数(记录数)
curl localhost:9200/_cluster/settings # 查看集群settings信息
curl localhost:9200/_tasks
curl http://localhost:9200/test-ziyi-1-100000-218/_mapping # 查看索引信息
curl -X GET "http://es.test.ziyi.com/test-ziyi-1-100004-100136/_doc/1?pretty" # 查询id为1的文档记录
curl http://localhost:9200/_cat/indices?v # 查看各个索引记录数,?v带上表头,展示详细信息
curl  -X DELETE "http://192.168.100.88:9200/my_index" # 删除索引(包含索引结构)
# 删除索引数据不包含索引结构
curl -X POST \-H 'Content-Type: application/json' \-d '{"query":{"match_all":{}}}' \'http://localhost:9200/test-ziyi-metadata-1-100004-100136/_delete_by_query?pretty=true' # 进入es pod,执行查询命令
curl -X POST "http://your_elasticsearch_host:9200/test-ziyi-metadata-1-10000-3/_search" -H 'Content-Type: application/json' -d '
{"size": 100,"sort": [{ "mtime": { "order": "desc" } },{ "key": { "order": "desc" } }],"query": {"range": {"size": {"gt": 10485760}}}
}'

例如:查看索引信息
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/46034.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

html表格账号密码备忘录:表格内容将通过JavaScript动态生成。点击查看密码10秒关闭

<!DOCTYPE html> <html lang"zh-CN"><head><meta charset"UTF-8"><title>账号密码备忘录</title><style>body {background: #2c3e50;text-shadow: 1px 1px 1px #100000;}/* 首页样式开始 */.home_page {color: …

《Linux系统编程篇》Visual Studio Code配置下载,中文配置,连接远程ssh ——基础篇

引言 vscode绝对值得推荐&#xff0c;非常好用&#xff0c;如果你能体会其中的奥妙的话。 工欲善其事&#xff0c;必先利其器 ——孔子 文章目录 引言下载VS Code配置VS Code中文扩展连接服务器 连接服务器测试确定服务器的IP地址VS code 配置ssh信息选择连接到主机选择这个添…

韦东山嵌入式linux系列-驱动设计的思想(面向对象/分层/分离)

1 面向对象 字符设备驱动程序抽象出一个 file_operations 结构体&#xff1b; 我们写的程序针对硬件部分抽象出 led_operations 结构体。 2 分层 上下分层&#xff0c;比如我们前面写的 LED 驱动程序就分为 2 层&#xff1a; ① 上层实现硬件无关的操作&#xff0c;比如注册…

防御第二次作业完成接口配置实验

一、实验括扑图 二、实验要求 1.防火墙向下使用子接口分别对应生产区和办公区 2.所有分区设备可以ping通网关 三、实验思路 1、配置各设备的IP地址 2、划分VLAN及VLAN的相关配置 3、配置路由及安全策略 四、实验步骤 1、配置PC跟Client还有server配置&#xff0…

【C++】初始化列表”存在的意义“和“与构造函数体内定义的区别“

构造函数是为了方便类的初始化而存在&#xff0c;而初始化时会遇到const成员变量、引用成员变量等&#xff0c;这些变量不允许函数内赋值&#xff0c;必须要在初始化时进行赋值&#xff0c;所以就有了初始化列表&#xff0c;初始化列表只能存在于类的构造函数中&#xff0c;用于…

Spring Boot快速上手

一&#xff0c;什么是spring 首先登陆Spring官网&#xff0c;看一下官网如何形容的&#xff0c; 可以看出Spring是为了使java程序更加快速&#xff0c;方便&#xff0c;安全所做出的java框架。 1.Spring Boot Spring Boot的诞生就是为了简化Spring的开发&#xff0c;也就是更…

gfast前端UI:基于Vue3与vue-next-admin适配手机、平板、pc 的后台开源模板

摘要 随着现代软件开发的高效化需求&#xff0c;一个能够快速适应不同设备、简化开发过程的前端模板变得至关重要。gfast前端UI&#xff0c;基于Vue3.x和vue-next-admin&#xff0c;致力于提供这样一个解决方案。本文将深入探讨gfast前端UI的技术栈、设计原则以及它如何适配手机…

【VS2019】安装下载库HtmlAgilityPack,可解析 HTML (图文详情)

目录 0.背景 1.环境 2.详细步骤 0.背景 项目需要&#xff0c;搭建WCF服务&#xff0c;需求是输入一个string类型字符串&#xff08;网页代码&#xff0c;如<html><body><p>Hello, <b>World</b>!</p></body></html>&#xf…

刷题之单词规律同构字符串(leetcode)

同构字符串 单词规律 两个都是映射关系&#xff0c;用两张哈希表记录互相映射就可以了 同构字符串&#xff1a; class Solution { public:bool isIsomorphic(string s, string t) {//用两张哈希表做映射if(s.size()!t.size()){return false;}unordered_map<char,char&…

清华计算几何-ConvexHull(凸包)-极点InTriangle/ToLeft Test

ConvexHull(凸包)的基本概念 给定一个点集, 求出最外围的点所形成的几何, 就是凸包。如下所示 凸包在计算几何是一个非常基础和核心的一个概念, 很多几何计算算法都围绕凸包展开。 极点和非极点 如上图所示, 蓝图圈圈住的点都是极端点, 极端点具备一个重要的特性: 极点(ext…

YOLOv10改进 | 特殊场景检测篇 | 单阶段盲真实图像去噪网络RIDNet辅助YOLOv10图像去噪(全网独家首发)

一、本文介绍 本文给大家带来的改进机制是单阶段盲真实图像去噪网络RIDNet&#xff0c;RIDNet&#xff08;Real Image Denoising with Feature Attention&#xff09;是一个用于真实图像去噪的卷积神经网络&#xff08;CNN&#xff09;&#xff0c;旨在解决现有去噪方法在处理…

c# 容器变换

List<Tuple<int, double, bool>> 变为List<Tuple<int, bool>>集合 如果您有一个List<Tuple<int, double, bool>>并且您想要将其转换为一个List<Tuple<int, bool>>集合&#xff0c;忽略double值&#xff0c;您可以使用LINQ的S…

卷积神经网络-猫狗识别实战

课程来自bilibiliMomodel平台 全长只有两个小时&#xff0c;理论部分讲得很粗糙 1 人的视觉和计算机视觉 人的大脑&#xff1a;神经元细胞&#xff0c;轴突发送信号&#xff0c;树突接收信号&#xff0c;互相连接&#xff0c;连接的强度和状态会随着新的经历刺激而变化。 用…

server nat表和会话表的作用及NAT地址转换详细

本章节主要讲nat技术的基础 -会话表的建立也是看5元组 -状态检测技术的回包一样也看5元组&#xff0c;但是状态检测技术会看的除开5元组还有更多东西 老哥&#xff0c;你真的应该好好注意一个东西&#xff1a;我们的会话表只是为了后续包的转发&#xff0c;会话表是记录的首…

【机器学习】和【人工智能】在航空航天中的应用

作者主页: 知孤云出岫 目录 引言机器学习和人工智能在航空航天中的应用1. 预测性维护2. 飞行路径优化3. 自动驾驶飞行器 未来展望1. 增强人机协作2. 更智能的空中交通管理3. 高效的航空制造 结论参考文献 引言 随着科技的迅猛发展&#xff0c;机器学习和人工智能&#xff08;…

【python报错已解决】 “Invalid Array Index“

&#x1f3ac; 鸽芷咕&#xff1a;个人主页 &#x1f525; 个人专栏: 《C干货基地》《粉丝福利》 ⛺️生活的理想&#xff0c;就是为了理想的生活! 文章目录 引言一、问题描述1.1 报错示例1.2 报错分析1.3 解决思路 二、解决方法&#xff1a;2.1 方法一&#xff1a;检查索引范…

win32:第一个窗口程序-应用程序入口点(part.6)

第一个窗口程序的最后一部分&#xff1a;应用程序入口函数wWinMain&#xff1b;这是Windows应用程序的主函数&#xff0c;负责初始化应用程序、注册窗口类、创建主窗口并进入消息循环处理消息。 int APIENTRY wWinMain(_In_ HINSTANCE hInstance,_In_opt_ HINSTANCE hPrevInst…

pytorch说明

深度学习中的重要概念&#xff1a; 激活函数&#xff1a; 激活函数的必要性&#xff1a;激活函数不是绝对必须的&#xff0c;但在深度学习中&#xff0c;它们几乎总是被使用。激活函数可以引入非线性&#xff0c;这使得神经网络能够学习更复杂的模式。 激活函数的位置&#x…

用HTML和CSS实现提示工具(tooltip)及HTML元素的定位

所谓提示工具&#xff0c;是指将鼠标移动到某个HTML元素&#xff08;工具&#xff09;时会显示一些提示内容&#xff08;提示文本&#xff09;&#xff0c;而鼠标移出工具元素的范围时提示文本就消失了。考虑到提示文本元素应当在鼠标进入工具元素时显示&#xff0c;鼠标离开工…

Mac安装stable diffusion 工具

文章目录 1.安装 Homebrew2.安装 stable diffusion webui 的依赖3.下载 stable diffusion webui 代码4.启动 stable diffusion webui 本体5.下载模型6.这里可能会遇到一个clip-vit-large-patch14报错 参考&#xff1a;https://brew.idayer.com/install/stable-diffusion-webui/…