索引库操作

mapping属性
mapping是对索引库中文档的约束,常见的mapping属性包含:

  • type:字段数据类型,常见的简单类型有
    - 字符串:text(可分词的文本)、keyword(精确值,例如:品牌、国家、ip地址)
    - 数值:long、integer、short、byte、double、float
    - 布尔:boolean
    - 日期:date
    - 对象:object (嵌套类)
  • index:是否创建索引,默认为true (true就可以搜索)
  • analyzer:使用哪种分词器(与text结合使用 )
  • properties:该字段的子字段(嵌套时使用)

创建索引库
格式

PUT /索引库名称
{
  "mappings": {
    "properties": {
      "字段名1": {
	    "type": "text",
		"analyzer": "ik_smart"
	  },
	  "字段名2": {
	    "type": "keyword",
		"index": "false"
	  },
	  "字段名3":{
	    "properties": {
		  "子字段": {
		    "type": "keyword"
		  }
		}
	  },
	  //略
	}
  }
}

eg:

PUT /yy
{
  "mappings": {
    "properties": {
      "info": {
	    "type": "text",
		"analyzer": "ik_smart"
	  },
	  "email": {
	    "type": "keyword",
		"index": "false"
	  },
	  "name":{
	    "type": "object",
	    "properties": {
		  "firstName": {
		    "type": "keyword"
		  },
		  "lastName": {
		    "type": "keyword"
		  }
		}
	  }
	}
  }
}

info是text,分词器用ik_smart
email是keywork,false不需要创建倒索引
name是object,properties表示有子字段

返回创建成功

{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "index" : "yy"
}

查看索引库

GET /索引库名

删除索引库

DELETE /索引库名

修改索引库

修改索引库会导致原倒排索引库失效,影响较大,所以ES不允许修改索引库。

索引库和mapping一旦创建无法修改,但是可以添加新的字段

PUT /索引库名/_mapping
{
  "properties": {
    "新字段名": {
	  "type": "integer"
	}
  }
}

eg:

PUT /yy/_mapping
{
  "properties": {
    "age": {
	  "type": "integer"
	}
  }
}

返回

{
  "acknowledged" : true
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值