ElasticSearch的使用

本文详细介绍了如何使用Elasticsearch进行索引的创建、删除及映射表的管理,包括通过DevTools和curl命令操作,以及如何进行type和mapping的新增与修改。并强调了高版本ES对String类型的弃用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

创建和删除索引

使用DevTools

 PUT test001
 DELETE test001

使用curl

curl -X PUT "http://10.5.145.101:9200/productindex"
curl -X DELETE "http://10.5.145.101:9200/productindex"

注意索引名称都是小写字母才行。

  • 创建type和对应的映射表
    查看
curl -XGET "http://10.5.145.101:9200/trolley/_mapping?pretty"
GET trolley/_mapping?pretty

新建type和对应的mapping
DEVTools

POST trolley/product/_mapping?pretty 
{
    "product": {
            "properties": {
                "price": {
                    "type": "double"
                },
                "onSale": {
                    "type": "boolean"
                },
                "type": {
                    "type": "integer"
                },
                "createDate": {
                    "type": "date"
                }
            }
        }
  }

注意,ES高版本中不再支持String,请不要在写Spring了。
增量修改mapping

POST trolley/product/_mapping?pretty 
{
     "product": {
                "properties": {
                     "amount":{
                        "type":"text"
                   }
                }
            }
    }

ES不支持非增量修改index,如果要修改,只能删除然后重建。

简单查询

POST /trolley/_search
{
  "query": { "match": { "eventType": "ISSUE" } }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值