注意:下面的操作是在kibana上进行的。在postman上进行时,需要填写IP:9200
1、查看状态
GET /_cat/health?v
2、查询索引全部数据
GET /ma_2020/_search
3、查询索引mapping
GET /ma_2020/_mapping
4、删除索引
DELETE /ma_2020
5、创建索引
PUT /ma_2020
6、设置mapping
PUT /qhpms_retail_headpremium/_mapping
{
"properties" : {
"@timestamp" : {
"type" : "date"
},
"@version" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"agent_name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"agent_no" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"c_crt_tm" : {
"type" : "date"
},
"dep" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"dept_code" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"dept_name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"insurance_preminum" : {
"type" : "float" #类型为long时,kibana小数点后面可能会被省略
},
"policy_create_time" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"type" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
7、时间范围查询
GET /ma_2020/_search
{
"query": {
"range": {
"@timestamp": {
"from": "2020-05-14T06:29:29.000Z",
"to": "2020-05-18T01:20:29.000Z"
}
}
}
}
8、查询并删除数据
GET /ma_2020/_delete_by_query
{
"query": {
"range": {
"@timestamp": {
"from": "2020-05-14T06:29:29.000Z",
"to": "2020-05-18T01:20:29.000Z"
}
}
}
}
9、导入一条数据
POST /pcis_work_dayly/_doc/123456789(唯一ID)
{
"dep_name": "广东分公司",
"name": "车险",
"network": "互联网",
"dayly_premium": 5,
"c_crt_tm": "2020-03-25",
"month_premium": 40,
"dayly_premium_icome": 5.03,
"year_premium_icome": 400,
"year_premium": 300,
"year_target": 2500,
"time_progress_task": 20.15
}
10、更改部分数据
如果docoment_id不存在会报错。所以需要优化。
POST spv_month_number/_update/广东2020-01-01
{
"doc":{
"dep" : "广东",
"spv_target" : 4.74,
"c_crt_tm" : "2020-01-01",
"month" : "1月",
"spv_number" : 6.39
}
}
如果ID不存在就插入。
POST spv_month_number/_update/广东2020-02-01
{
"doc":{
"spv_number" : 7.39
},
"doc_as_upsert": true
}
11、字段存在
字段的存在,使用关键字 exists。
GET spv_month_number/_search
{
"query": {
"bool": {
"must": [
{
"exists": {
"field": "kv.n"
}
}
]
}
}
}
复杂操作可以查看我另外的文章。
ElasticSearch中distinct,count和group by的实现
ElasticSearch进行and,or,in,not in多条件组合DSL结构化查询