在《玩玩儿Elasticsearch》中简单介绍了一下elasticsearch。这篇文章,我们还是做些基础的学习,在Elasticsearch如何进行CRUD?
课程推荐→:《elasticsearch全文搜索实战》(实战视频)
假设我们正在创建的一个类似微博的应用,我们就姑且先叫它“kiwi”吧。kiwi这个应用就是一条条消息组成的。
在kiwi中,消息称为ksay。有两个部分组成,一是作者(author),而是消息本身(message)。
Create
curl -X POST http://localhost:9200/kiwi/ksay/ -d '{ "author": "rococojie", "message": "I am beautiful"}'
返回:{"_index":"kiwi","_type":"ksay","_id":"aaX3P2LJSP-dDYVy0USv7Q","_version":1,"created":true}
我们注意到elasticsearch默认不是按照自增的方式帮我们生成id的。而是自动生成22位的URL安全的_id。如刚才的例子中,返回的_id就是aaX3P2LJSP-dDYVy0USv7Q。如果要使用自定义的_id,则操作如下:
curl -X POST http://localhost:9200/kiwi/ksay/1 -d '{"author": "jerry", "message": "I hate Tom"}'
返回:{"_index":"kiwi","_type":"ksay","_id":"1","_version":1,"created":true}
Read
我们这里就只说用id取值
curl -X GET http://localhost:9200/kiwi/ksay/1
返回:{"_index":"kiwi","_type":"ksay","_id":"1","_version":1,"found":true, "_source" : { "author": "jerry", "message": "I hate Tom"}}
如果我们希望返回的知识原来我们存的数据,那么
curl -X GET http://localhost:9200/kiwi/ksay/1/_source
返回:{ "author": "jerry", "message": "I hate Tom"}
curl -X GET http://localhost:9200/kiwi/ksay/10000
返回{"_index":"kiwi","_type":"ksay","_id":"10000","found":false},没有找到我们刚才存的ksay。
Update
curl -X PUT http://localhost:9200/kiwi/ksay/1 -d '{"author": "jerry", "message": "I love Tom"}'
返回:{"_index":"kiwi","_type":"ksay","_id":"1","_version":2,"created":false}
我们注意到这里的_version变为了2,知识因为ksay发生了改变。created返回false,表示没有创建新的文档,只是更新。
虽然Elasticsearch支持进行文档更新,我们需要知道Elasticsearch中存储的文档是不可变的(immutable)。这种所谓的更新实际上是一种假象,在Elasticsearch内部,首先将比较旧的那条数据标明为“已经删除”,然后再把较新的那条数据进行index。(retrieve-change-reindex)
部分更新
curl -X POST http://localhost:9200/kiwi/ksay/1/_update -d '{ "doc": {"message": "I hate Tom, again"} }'
返回:{"_index":"kiwi","_type":"ksay","_id":"1","_version":3}
"doc"中即是我们需要更新的field。Elasticsearch会把最新的field“merge”到原来旧的文档中。这是我们再去查看这条ksay的信息。
curl -X GET http://localhost:9200/kiwi/ksay/1
返回:{"_index":"kiwi","_type":"ksay","_id":"1","_version":3,"found":true, "_source" : {"author":"jerry","message":"I hate Tom, again"}}
Delete
curl -X DELETE http://localhost:9200/kiwi/ksay/1
返回:{"found":true,"_index":"kiwi","_type":"ksay","_id":"1","_version":4}
再尝试去取ksay:
curl -X GET http://localhost:9200/kiwi/ksay/1
返回:{"_index":"kiwi","_type":"ksay","_id":"1","found":false}
就不能在访问到,found的值是false
学会了Elasticsearch最基本的CRUD,我们可以再找些其他好玩儿的来玩儿了

todropaviewInmySQL,使用“ dropviewifexistsview_name;” andTomodifyAview,使用“ createOrreplaceViewViewViewview_nameAsSelect ...”。 whendroppingaview,asew dectivectenciesanduse和showcreateateviewViewview_name;“ tounderStanditSsstructure.whenModifying

mySqlViewScaneFectectialized unizedesignpatternslikeadapter,Decorator,Factory,andObserver.1)adapterPatternadaptSdataForomDifferentTablesIntoAunifiendView.2)decoratorPatternenhancateDataWithCalcalcualdCalcalculenfields.3)fieldfields.3)

查看InMysqlareBeneForsImplifyingComplexqueries,增強安全性,確保dataConsistency,andOptimizingPerformance.1)他們simimplifycomplexqueriesbleiesbyEncapsbyEnculatingThemintoreusableviews.2)viewsEnenenhancesecuritybyControllityByControllingDataAcces.3)

toCreateAsimpleViewInmySQL,USEthecReateaTeviewStatement.1)defitEtheetEtheTeViewWithCreatEaTeviewView_nameas.2)指定usethectstatementTorivedesireddata.3)usethectStatementTorivedesireddata.3)usetheviewlikeatlikeatlikeatlikeatlikeatlikeatable.views.viewssimplplifefifydataaccessandenenanceberity but consisterfort,butconserfort,consoncontorfinft

1)foralocaluser:createUser'localuser'@'@'localhost'Indidendify'securepassword'; 2)foraremoteuser:creationuser's creationuser'Remoteer'Remoteer'Remoteer'Remoteer'Remoteer'Remoteer'Remoteer'Remoteer'Rocaluser'@'localhost'Indidendify'seceledify'Securepassword'; 2)

mysqlviewshavelimitations:1)他們不使用Supportallsqloperations,限制DatamanipulationThroughViewSwithJoinsOrsubqueries.2)他們canimpactperformance,尤其是withcomplexcomplexclexeriesorlargedatasets.3)

porthusermanagementinmysqliscialforenhancingsEcurityAndsingsmenting效率databaseoperation.1)usecReateusertoAddusers,指定connectionsourcewith@'localhost'or@'%'。

mysqldoes notimposeahardlimitontriggers,butacticalfactorsdeterminetheireffactective:1)serverConfiguration impactactStriggerGermanagement; 2)複雜的TriggerSincreaseSySystemsystem load; 3)largertablesslowtriggerperfermance; 4)highConconcConcrencerCancancancancanceTigrignecentign; 5); 5)


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

禪工作室 13.0.1
強大的PHP整合開發環境

SublimeText3漢化版
中文版,非常好用