注:7.0之后,type默认都是_doc
elasticsearch创建文档有两种方式,1是POST,2是PUT,post是让elasticsearch自动生成id,而通过put,我们可以自己指定id
指定id为1(如果id已经存在,则直接报错)
PUT my_index/_doc/1?op_type=create { "username": "pibigsrar" "age": 12 }它会先删除原先id为1的文档,并把新的文档设置进去
PUT my_index/_doc/1 { "username": "pibigsrar" }你可以通过这个新增一个字段或修改某个字段的值
POST my_index/_update/1 { "doc": { "username": "test" "sex": 1 } }根据id获取
GET my_index/_doc/1批量执行操作,操作可以是查询,创建,删除,搜索等
POST _bulk { "index" : { "_index" : "test", "_id" : "1" } } { "field1" : "value1" } { "delete" : { "_index" : "test", "_id" : "2" } } { "create" : { "_index" : "test2", "_id" : "3" } } { "field1" : "value3" } { "update" : {"_id" : "1", "_index" : "test"} } { "doc" : {"field2" : "value2"} }批量获取
GET my_index/_mget { "docs" : [ { "_id" : "1" }, { "_id" : "2" } ] }不同的index
GET /_mget { "docs" : [ { "_index" : "my_index", "_id" : "1" }, { "_index" : "test", "_id" : "2" } ] }批量搜索
POST my_index/_msearch {} {"query" : {"match_all" : {}},"size":1} {"index" : "kibana_sample_data_flights"} {"query" : {"match_all" : {}},"size":2}根据contentId 去重
"aggs": { "distinct_contentId": { "cardinality": { "field": "contentId", } } }根据contentId分组count
"aggs": { "label_group": { "terms": { "field": "contentId" } } }