ElasticSearch怎么添加索引

发布时间:2021-03-11 17:03:52 作者:TREX
来源:亿速云 阅读:393

本篇内容主要讲解“ElasticSearch怎么添加索引”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“ElasticSearch怎么添加索引”吧!

1. 编写索引内容

  节点解释:

  settings:配置信息

  "number_of_replicas": 0 不需要备份(单节点的ElasticSearch使用)

  "mappings": 映射内容

  "dynamic":false 是否动态索引,这里使用的是false,表示索引的固定的,不需要修改。

  "properties": 属性结构内容

  "index":"true" 需要分词处理的结构

  type对应的数据类型,text文本(长字符串),integer数字,date时间,keyword单词

elasticsearch 6.X版本的索引文件

{
 "settings":{
  "number_of_replicas": 0
 },
 "mappings":{
  "house":{
   "dynamic":false,
   "properties":{
    "houseId":{"type":"long"},
    "title":{"type":"text", "index":"true"},
    "price":{"type":"integer"},
    "area":{"type":"integer"},
    "createTime":{"type":"date","format":"strict_date_optional_time||epoch_millis"},
    "lastUpdateTime":{"type":"date", "format":"strict_date_optional_time||epoch_millis"},
    "cityEnName":{"type":"keyword"},
    "regionEnName":{"type":"keyword"},
    "direction":{"type":"integer"},
    "distanceToSubway":{"type":"integer"},
    "subwayLineName":{"type":"keyword"},
    "subwayStationName":{"type":"keyword"},
    "tags":{"type":"text"},
    "district":{"type":"keyword"},
    "description":{"type":"text", "index":"true"},
    "layoutDesc":{"type":"text", "index":"true"},
    "traffic":{"type":"text", "index":"true"},
  "roundService": {"type": "text", "index": "true"},
    "rentWay":{"type":"integer"}
   }
  }
 }
}

elasticsearch 7.X版本的索引文件

{
 "settings":{
  "number_of_replicas": 0
 },
 "mappings":{
  "dynamic":false,
  "properties":{
   "title":{"type":"text", "index":"true"},
   "price":{"type":"integer"},
   "area":{"type":"integer"},
   "createTime":{"type":"date","format":"strict_date_optional_time||epoch_millis"},
   "lastUpdateTime":{"type":"date", "format":"strict_date_optional_time||epoch_millis"},
   "cityEnName":{"type":"keyword"},
   "regionEnName":{"type":"keyword"},
   "direction":{"type":"integer"},
   "distanceToSubway":{"type":"integer"},
   "subwayLineName":{"type":"keyword"},
   "subwayStationName":{"type":"keyword"},
   "tags":{"type":"text"},
   "district":{"type":"keyword"},
   "description":{"type":"text", "index":"true"},
   "layoutDesc":{"type":"text", "index":"true"},
   "traffic":{"type":"text", "index":"true"},
  "roundService": {"type": "text", "index": "true"},
   "rentWay":{"type":"integer"}
  }
 }
}

2. 创建索引

  使用Postmen发送创建索引请求

ElasticSearch怎么添加索引

  (1)地址栏后半段是索引名称

  (2)请求使用的PUT方式,选择Body,raw形式,采用JSON格式发送

  创建成功的显示结果:

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

  在ElasticSearch-Head里查看结果:

3. 创建索引时的报错:

  错误1:Root mapping definition has unsupported parameters

  原因:ElasticSearch7.X之后的版本默认不在支持指定索引类型,默认索引类型是_doc(隐含:include_type_name=false),所以在mappings节点后面,直接跟properties就可以了。

ElasticSearch怎么添加索引

  问题2:Could not convert [title.index] to boolean

  原因:也是新版本的问题,之前版本的index属性写法是"analyze",现在只能设置true, false, "true","false"

到此,相信大家对“ElasticSearch怎么添加索引”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

推荐阅读:
  1. Elasticsearch 索引文档
  2. elasticsearch索引性能优化

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

elasticsearch

上一篇:SpringBoot项目中优化和垃圾回收器的对比分析

下一篇:Golang HTTP 服务平滑怎么重启和升级

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》