Elasticsearch基础命令使用

注:7.0之后,type默认都是_doc,增删改时需要加type,但查询时不用加

创建文档

elasticsearch创建文档有两种方式,1是POST,2是PUT,post是让elasticsearch自动生成id,而通过put,我们可以自己指定id

自动生成id

POST my_index/_doc
{
	"username": "pibigsrar"
	"age": 12
}

自定义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
	}
}

删除

DELETE my_index/_doc/1

读取

GET

根据id获取

GET my_index/_doc/1

bulk

批量执行操作,操作可以是查询,创建,删除,搜索等

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"} }

mget

批量获取

GET my_index/_mget
{
    "docs" : [
        {

            "_id" : "1"
        },
        {

            "_id" : "2"
        }
    ]
}

不同的index

GET /_mget
{
    "docs" : [
        {
            "_index" : "my_index",
            "_id" : "1"
        },
        {
            "_index" : "test",
            "_id" : "2"
        }
    ]
}

msearch

批量搜索

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"
      }
    }
}

2. 笔记

2.1 URL Search




![](https://img-blog.csdnimg.cn/04f07ed6cbd64d128ee4e8bfdcc98562.png)
![](https://img-blog.csdnimg.cn/d8020441f4194e9e92dc03f53f7f7bce.png)
![](https://img-blog.csdnimg.cn/2cbbade33be74d8bb803ec2b681d5d01.png)

2.2 Request Body


![](https://img-blog.csdnimg.cn/9647424368da4740a12d80e56d8c8362.png)

![](https://img-blog.csdnimg.cn/9ce67d4dacc6494e8dae390e53a7f1a3.png)

2.3 mapping






















2.4 template

template

2.5 聚合分析aggregations

聚合分析aggregations

2.6 curd

curd

2.7 倒排索引

倒排索引

2.8 Analyzer

analyzer

2.9 结构化搜索

结构化搜索

2.10 term查询

term查询

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值