成都网站建设设计

将想法与焦点和您一起共享

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

另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前题目:ElasticSearch怎么添加索引-创新互联
文章URL:http://chengdu.cdxwcx.cn/article/cejgij.html