ElasticSearch添加索引代码实例解析
作者:闲人鹤 发布时间:2023-11-21 03:41:04
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发送创建索引请求
(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就可以了。
问题2:Could not convert [title.index] to boolean
原因:也是新版本的问题,之前版本的index属性写法是"analyze",现在只能设置true, false, "true","false"
来源:https://www.cnblogs.com/huanshilang/p/12616310.html


猜你喜欢
- WPF实现滚动条还是比较方便的,只要在控件外围加上ScrollViewer即可,但美中不足的是:滚动的时候没有动画效果。在滚动的时候添加过渡
- NuGet 安装SqlSugar1.Model文件下新建 DbContext 类 public class DbContext
- 1. 前言Spring的核心技术IOC(Intorol of Converse控制反转)的实现途径是DI(dependency Insert
- 双向循环链表定义相比于单链表,有两个指针,next指针指向下一个结点,prior指针指向上一个结点,最后一个结点的next指针指向头结点,头
- 一、结构型模式结构型模式有什么好处?从程序的结构上实现松耦合,从而可以扩大整体的类结构,用来解决更大的问题二、适配器模式USB网线转换器三、
- 前言说起Android进行间通信,大家第一时间会想到AIDL,但是由于Binder机制的限制,AIDL无法传输超大数据。那么我们如何在进程间
- 只要是面向对象的编程语言,基本上都有类Class的用法,只是好不好用,好不好记而已,面向对象是c++开始引入的,但是c++ 关于类的东西,弄
- 使用JPA CriteriaQuery查询的注意事项1.pojo类@Entity@Table(name = "report_wor
- 目录1 创建 xml 动画文件2 加载使用3 聊一聊 AnimationDrawable3.1 使用 ViewTreeObserver3.2
- 如何使用 Jetpack Compose 创建翻转卡片效果介绍在电子商务和银行应用程序中输入卡信息是很常见的情况。我认为让用户更轻松地处理这
- 一. CodeCache简介从字面意思理解就是代码缓存区,它缓存的是JIT(Just in Time)编译器编译的代码,简言之codeCac
- spring容器初始化Bean操作在某些情况下,Spring容器在初始化Bean的时候,希望在初始化bean前和销毁bean前进行一些资源的
- 前言在开发中我们经常要使用图片或者drawable文件夹下的xml,来实现一些效果,Drawable的用法都和xml相关,我们可以使用sha
- 在springboot项目中如果要在不集成templates的情况下访问静态资源需要做以下配置1.在项目的application.yml文件
- 这两天做了一个项目,发现标签不能更改任意一个标签的字体的颜色,需求如同置前标签,然后就对tagcloudeview稍做修改做了这么一个dem
- 1.Action中的validate()方法Struts2提供了一个Validateable接口,这个接口中只存在validat
- 如果还不知道DecorView,那也没有什么关系 ^_^先来看看实现的效果实现的大致思路首先需要明白什么是DecorView,他是andro
- 今天看到一篇好的文章,分享给大家,膜拜大佬。Android10填坑适配指南,包含实际经验代码,绝不照搬翻译文档1.Region.Op相关异常
- Android系统提供了MediaScanner,MediaProvider,MediaStore等接口,并且提供了一套数据库表格,通过Co
- 系统有很多光标类型 :Cursors 类 (System.Windows.Input) | Microsoft Docs本章介绍如何自定义光