资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

ElasticSearch怎么添加索引

本篇内容主要讲解“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怎么添加索引”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!


本文名称:ElasticSearch怎么添加索引
文章起源:http://cdkjz.cn/article/psisdi.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220