ElasticSearch RESTFUL API的简单操作(增删改查)

注意:下面的操作是在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结构化查询

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值