文檔基本操作

      網(wǎng)友投稿 624 2022-05-29

      文檔的基本操作

      新增文檔

      # 創(chuàng)建索引 curl -X PUT "http://localhost:9200/student" # 創(chuàng)建mapping curl -X PUT "localhost:9200/student/_mapping" -H 'Content-Type: application/json' -d' { "properties": { "name": { "type": "text" }, "years":{ "type": "integer" } } } ' # 指定ID新增文檔 curl -X PUT "localhost:9200/student/_doc/1" -H "Content-Type: application/json" -d' { "name": "Nick", "age": 19 } ' # 不指定ID新增文檔 curl -X POST "localhost:9200/student/_doc" -H "Content-Type: application/json" -d' { "name": "Nick", "age": 19 } '

      指定操作類型

      # 創(chuàng)建文檔,如果該文檔已經(jīng)存在則會(huì)UPDATE curl -X PUT "localhost:9200/student/_doc/1" -H "Content-Type: application/json" -d' { "name": "Nick", "age": 35 } ' # 指定創(chuàng)建操作,如果該文檔已經(jīng)存在則會(huì)報(bào)錯(cuò),該操作可以避免錯(cuò)誤 curl -X PUT "localhost:9200/student/_doc/1?op_type=create" -H "Content-Type: application/json" -d' { "name": "Nick", "age": 35 } '

      查看文檔

      # 通過(guò)ID查看文檔 curl -X GET "localhost:9200/student/_doc/1" curl -X POST "localhost:9200/_mget?pretty" -H "Content-Type: application/json" -d ' { "docs":[ { "_index": "student", "_type": "_doc", "_id": "1" }, { "_index": "school", "_type": "_doc", "_id": "1" } ] } ' # 指定索引,然后獲取多個(gè)ID值的文檔 curl -X POST "localhost:9200/student/_mget?pretty" -H "Content-Type: application/json" -d ' { "docs":[ { "_type": "_doc", "_id": "1" }, { "_type": "_doc", "_id": "2" } ] } ' # 指定索引,文檔,然后獲取多個(gè)ID值的文檔 curl -X POST "localhost:9200/student/_doc/_mget?pretty" -H "Content-Type: application/json" -d ' { "docs":[ { "_id": "1" }, { "_id": "2" } ] } ' curl -X POST "localhost:9200/student/_doc/_mget?pretty" -H "Content-Type: application/json" -d ' { "ids": [1,2] } '

      修改文檔

      # 指定id修改 curl -X POST "localhost:9200/student/_update/1" -H "Content-Type: application/json" -d ' { "doc": { "name": "Elaine" } } ' curl -X GET "localhost:9200/student/_doc/1?pretty" # 新增字段,ctx上下文 curl -X POST "localhost:9200/student/_update/1" -H "Content-Type: application/json" -d ' { "script": "ctx._source.age1 = 19" } ' # 刪除字段,ctx上下文 curl -X POST "localhost:9200/student/_update/1" -H "Content-Type: application/json" -d ' { "script": "ctx._source.remove(\"age1\")" } ' # 更新, upsert當(dāng)文檔不存在時(shí),upsert內(nèi)的內(nèi)容將會(huì)插入到索引中,作為一個(gè)新文檔 curl -X POST "localhost:9200/student/_update/1" -H "Content-Type: application/json" -d ' { "script": { "source": "ctx._source.age += params.age", "params": { "age": 4 } }, "upsert":{ "age": 1 } } '

      文檔的基本操作

      刪除

      # 刪除指定文檔 curl -X DELETE "localhost:9200/student/_doc/1" -H "Content-Type: application/json"

      自動(dòng)創(chuàng)建索引

      當(dāng)索引不存在,并且auto_create_index為true的時(shí),新增文檔會(huì)自動(dòng)創(chuàng)建索引

      # 查看方法 curl http://localhost:9200/_cluster/settings # 配置方法 curl -X PUT "localhost:9200/_cluster/settings" -H "Content-Type: application/json" -d' { "persistent": { "action.auto_create_index": "true" } } '

      Elasticsearch

      版權(quán)聲明:本文內(nèi)容由網(wǎng)絡(luò)用戶投稿,版權(quán)歸原作者所有,本站不擁有其著作權(quán),亦不承擔(dān)相應(yīng)法律責(zé)任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實(shí)的內(nèi)容,請(qǐng)聯(lián)系我們jiasou666@gmail.com 處理,核實(shí)后本網(wǎng)站將在24小時(shí)內(nèi)刪除侵權(quán)內(nèi)容。

      上一篇:K8s 原理架構(gòu)介紹(一)
      下一篇:接口測(cè)試--接口文檔規(guī)范
      相關(guān)文章
      国产精品高清视亚洲一区二区| 日韩精品一区二区亚洲AV观看| 国产v亚洲v天堂无码网站| 亚洲熟妇AV一区二区三区浪潮| 亚洲乱码中文论理电影| 亚洲精品国产福利片| 久久亚洲AV成人出白浆无码国产| 亚洲视频在线免费观看| 久久亚洲精品无码| 亚洲国产精品久久久久久| 亚洲大尺度无码专区尤物| 亚洲第一成年男人的天堂| 久久亚洲日韩精品一区二区三区| 亚洲高清中文字幕综合网| 久久综合亚洲色HEZYO社区| 亚洲精品免费在线视频| 亚洲国产成a人v在线| 亚洲第一页在线视频| 亚洲AV成人噜噜无码网站| 亚洲黄色三级视频| 亚洲国产高清在线精品一区| 亚洲成人黄色网址| 亚洲免费福利在线视频| 亚洲一区二区三区在线观看网站| 亚洲精品理论电影在线观看| MM1313亚洲国产精品| 亚洲免费日韩无码系列| 国产亚洲日韩在线三区| 国产成人精品日本亚洲| 亚洲午夜未满十八勿入| 亚洲人成网网址在线看| 在线观看日本亚洲一区| 狠狠入ady亚洲精品| 亚洲真人日本在线| 亚洲AV午夜成人片| 亚洲精品在线电影| 亚洲日韩中文字幕一区| 337P日本欧洲亚洲大胆精品| 久久久久亚洲精品天堂久久久久久| 亚洲无人区一区二区三区| 亚洲AV乱码久久精品蜜桃|