Elasticsearch之-文件操作
阿新 • • 發佈:2021-06-15
#新增一個id為1的書籍(POST和PUT都可以) POST lqz/_doc/1/_create #POST lqz/_doc/1 #POST lqz/_doc 會自動建立id,必須用Post { "title":"紅樓夢", "price":12, "publish_addr":{ "province":"黑龍江", "city":"鶴崗" }, "publish_date":"2013-11-11", "read_num":199, "tag":["古典","名著"] }
#查詢lqz索引下id為7的文件 GET lqz/_doc/7 #查詢lqz索引下id為7的文件,只要title欄位 GET lqz/_doc/7?_source=title #查詢lqz索引下id為7的文件,只要title和price欄位 GET lqz/_doc/7?_source=title,price #查詢lqz索引下id為7的文件,要全部欄位 GET lqz/_doc/7?_source
#修改文件(覆蓋修改) PUT lqz/_doc/10 { "title":"xxxx", "price":333, "publish_addr":{ "province":"黑龍江", "city":"福州" } } #修改文件,增量修改,只修改某個欄位(注意是post)POST lqz/_update/10 { "doc":{ "title":"修改" } }
#刪除文件id為10的 DELETE lqz/_doc/10
#批量獲取lqz索引_doc型別下id為2的資料和lqz2索引_doc型別下id為1的資料 GET _mget { "docs":[ { "_index":"lqz", "_type":"_doc", "_id":2 }, { "_index":"lqz2", "_type":"_doc","_id":1 } ] } #批量獲取lqz索引下id為1和2的資料 GET lqz/_mget { "docs":[ { "_id":2 }, { "_id":1 } ] } #同上 GET lqz/_mget { "ids":[1,2] }
PUT test/_doc/2/_create { "field1" : "value22" } POST _bulk { "index" : { "_index" : "test", "_id" : "1" } } { "field1" : "value1" } { "delete" : { "_index" : "test", "_id" : "2" } } { "create" : { "_index" : "test", "_id" : "3" } } { "field1" : "value3" } { "update" : {"_id" : "1", "_index" : "test"} } { "doc" : {"field2" : "value2"} }