es-04-mapping和setting的建立
mapping和setting, 使用java客户端比较难组装, 可以使用python或者scala
这儿直接在kibana中进行DSL创建
1, mapping
创建索引的时候, 可以事先对数据进行定义, 告诉es如果索引数据并被搜索
实际上, es会猜测原数据并判断, 但对一些特俗的字段, 需要指定
类型
类型: text, keyword(弃用) 数据: long, integer, short, byte, double, float 日期: date bool类型: boolean binary: binary 复杂类型: object (内置对象, dict), nested (把object 放在数组中) geo类型, geo-point, geo-shape 专业: ip, competion
mapping中, 新的数据 类型相比之前的发生了变化, keyword类型被弃用(v5.x)
- a simple type like
text,keyword,date,long,double,booleanorip.- a type which supports the hierarchical nature of JSON such as
objectornested. - or a specialised type like
geo_point,geo_shape, orcompletion.
- a type which supports the hierarchical nature of JSON such as
属性:
store: 是否存储, 适合all
index, 是否分析, 适合string
null_value: 字段为空, 可设置默认值 NA, 搜索时可以搜搜, 适合all
analyzer: 分词器, 默认 standard, 一般设置 ik。 适合。all
include_in_all: 默认es对每个文档设置一个, 让每个字段被搜索到, 如果不想搜索到,
就可以设置false
format: 格式化
1, 创建index
PUT test
{
"settings" : {
"number_of_shards" :
},
"mappings" : {
"type1" : {
"properties" : {
"field1" : { "type" : "text" }
}
}
}
}
mapping 和 type 必须那样写
2, 删除
DELETE /twitter
3, 查看
GET /twitter
4, exists
HEAD twitter
5, 索引开关
关闭后的索引, 节省资源, 仅仅维持原数据, 不进行读写操作, 还可以在mapping更新的时候进行
POST /my_index/_close POST /my_index/_open
6, 减少索引
注意: 素数只能缩减为素数
1), 创建一个新的包含更少分片的索引
2), 将segement 从 source index 硬连接到 target source
3) 恢复索引
PUT /my_source_index/_settings
{
"settings": {
"index.routing.allocation.require._name": "shrink_node_name",
"index.blocks.write": true
}
}
POST my_source_index/_shrink/my_target_index
7, split, 扩大分片
过程和减少类似, 对于已有的数据, 可修改副本, 不可修改分片, 因为数据位置需要分片数来确定, 一旦修改, 之前的就无效了
a) 准备用于切分的库
PUT my_source_index
{
"settings": {
"index.number_of_shards" : ,
"index.number_of_routing_shards" :
}
}
b), 切分
POST my_source_index/_split/my_target_index
{
"settings": {
"index.number_of_shards":
}
}
c), 创建硬连接
POST my_source_index/_split/my_target_index
{
"settings": {
"index.number_of_shards":
},
"aliases": {
"my_search_indices": {}
}
}
8, 滚动索引:
rollover index 当原索引太旧或者太老的时候, 可以滚动到新的索引上
9, put mapping
put mapping可以对一个已有的index添加字段等
PUT my_index
{
"mappings": {
"_doc": {
"properties": {
"name": {
"properties": {
"first": {
"type": "text"
}
}
},
"user_id": {
"type": "keyword"
}
}
}
}
} PUT my_index/_mapping/_doc
{
"properties": {
"name": {
"properties": {
"last": {
"type": "text"
}
}
},
"user_id": {
"type": "keyword",
"ignore_above":
}
}
}
10, get mapping
GET /twitter/_mapping/_doc
11, 查看某一个字段的属性
准备mapping
PUT publications
{
"mappings": {
"_doc": {
"properties": {
"id": { "type": "text" },
"title": { "type": "text"},
"abstract": { "type": "text"},
"author": {
"properties": {
"id": { "type": "text" },
"name": { "type": "text" }
}
}
}
}
}
}
GET publications/_mapping/_doc/field/title
或者使用通配符的方式
GET publications/_mapping/_doc/field/a*
12 type exists
HEAD twitter/_mapping/tweet
13 为索引设置别名
POST /_aliases
{
"actions" : [
{ "add" : { "index" : "test1", "alias" : "alias1" } }
]
}
删除
POST /_aliases
{
"actions" : [
{ "remove" : { "index" : "test1", "alias" : "alias1" } }
]
}
为多个索引创建同一个别名(感觉像联合索引)
POST /_aliases
{
"actions" : [
{ "add" : { "indices" : ["test1", "test2"], "alias" : "alias1" } }
]
}
14 更新索引
POST /twitter/_close PUT /twitter/_settings
{
"analysis" : {
"analyzer":{
"content":{
"type":"custom",
"tokenizer":"whitespace"
}
}
}
} POST /twitter/_open
15, get 索引
GET /twitter,kimchy/_settings
16 analyze, 进行分词预计
GET _analyze
{
"analyzer" : "standard",
"text" : ["this is a test", "the second text"]
}
explain
GET _analyze
{
"tokenizer" : "standard",
"filter" : ["snowball"],
"text" : "detailed output",
"explain" : true,
"attributes" : ["keyword"]
}
一个完整的mapping的示例
put macsearch_fileds
{
"settings": {
"number_of_shards": "",
"number_of_replicas": ""
},
"mappings": {
"mac": {
"dynamic": "true",
"properties": {
"app_name": {
"type": "keyword",
"index_options": "freqs"
},
"content": {
"type": "text",
"index_options": "offsets"
},
"current_time": {
"type": "long"
},
"mac": {
“store”: “false”,
"type": "keyword",
"index_options": "freqs"
},
"server_time": {
"type": "long"
},
"time": {
"type": "text",
"index_options": "freqs"
},
"topic": {
“stroe”: “true”,
"type": "keyword",
"index_options": "freqs",
“analyzer”: “ik_max_word”
}
}
}
}
}
dynamic取值:
true:默认值,动态添加字段;
false:忽略新字段;
strict:碰到陌生字段,抛出异常。
index_options :
index_options 参数用于控制增加到倒排索引的信息,为了搜索和高亮。它可以接受如下设置:
docs: 只索引文档号。可以用于回答词项是否存在于文档中的这个域。
freqs: 文档号和词频都会被存储. 词项频率越高积分越高。
positions: 文档号,词项,还有词的位置被索引。位置可以用于模糊或者短语查询。
offsets: 文档号,词项,词的位置,和开始到结束的字符偏移(词项映射到原来的字符串)被索引。 偏移提供postings highlighter。
分析字符串域默认是会使用positions,其他域默认使用docs。
如果有的字段只想索引, 不想存储, 可以使用 _source
put security_2
{
"settings": {
"number_of_shards": "",
"number_of_replicas": ""
},
"mappings": {
"push": {
"dynamic": "true",
"_source": {
"excludes": ["AesPhoneNum", "AesEmail"]
},
"properties": {
"AesPhoneNum": {
"type": "keyword",
"store": "false",
"index_options": "freqs"
},
"AesEmail": {
"type": "keyword",
"store": "false",
"index_options": "freqs"
}
}
}
}
}
对于有数据的需要更改的mapping
close index
post mapping
open index
这样可以保证原数据不丢, 但执行过程中会丢掉执行过程的1-2s的数据
2, setting
1), 可以对一个正在运行的集群进行扩容
将原 1 个副本, 扩大为2个副本
PUT /blogs/_settings
{
"number_of_replicas" :
}
但主分片的数量无法更改, 因为分片的位置需要 分片数量来确定, 如果更改, 那么之前存储的数据将无效
所以不允许修改
3, ik分词器
只需要在需要安装的位置, 进行添加ik分词即可
put macsearch_fileds
{
"settings": {
"number_of_shards": "",
"number_of_replicas": ""
},
"mappings": {
"mac": {
"dynamic": "true",
"properties": {
"app_name": {
"type": "keyword",
"index_options": "freqs"
},
"topic": {
"type": "keyword",
"index_options": "freqs",
“analyzer”: “ik_max_word” }
}
}
}
}
所有的分词器, 如果有index属性的话, 做分词的时候会进行大小写转换,
而term在查询的时候, 会原样查询, 所以如果有大写可能会匹配不到
es-04-mapping和setting的建立的更多相关文章
- Ubuntu 20.04 手动安装 sublime_text 并建立搜索栏图标(解决 Ubuntu 20.04 桌面图标无法双击打开问题)
下载sublime_text_3离线程序包 wget https://download.sublimetext.com/sublime_text_3_build_3211_x64.tar.bz2 #x ...
- es的mapping设置
自定义mapping的api PUT test_index { "mappings": { #mappings关键字 "doc": { #type " ...
- ES 04 - 安装Kibana插件(6.6.0版本)
目录 1 Kibana是什么 2 安装并启动Kibana 2.1 准备安装包 2.2 修改配置文件 2.3 启动Kibana并验证 2.4 关闭Kibana服务 3 Kibana功能测试 3.1 关于 ...
- ES创建mapping时字段别名
ES默认是动态创建索引和索引类型的mapping的,但是在学习的时候还能这样用,在生产中一定是手动制定mapping!在生产中经常会遇到这样的需求,想用某个字段进行统计,又想对该字段进行模糊查询,解决 ...
- ES 创建mapping
mapping的写入与查看首先创建一个索引: curl -XPUT "http://erp2.es.kd1.pagoda.com.cn:80/erp_stock_index"{&q ...
- [Elasticsearch] ES 的Mapping 设计在实际场景中应用
背景 项目中有个需求是需要几个字段作为标签,统计各个标签的文档数量,同时支持分词后的全文检索功能. 原有的mapping设计: curl -XPUT http://ip:9200/meta_es_me ...
- es-06-java创建mapping和setting
说实话, java的方式太繁琐, 不如直接使用DSL进行创建 1, create package com.wenbronk.elasticsearch.usage.index; import com. ...
- es put mapping
fd dg public Map<String, Map<String, String>> javaBeanToMapping(Object instance, List< ...
- es 修改 mapping 字段类型
一.原索引 PUT my_index { "mappings": { "_doc": { "properties": { "cre ...
随机推荐
- 位图bitbucket
问题:假设有500w条数据,数据是在2^32-1的范围内,数据重复,如何减少内存对数字进行统计呢? 如果用字典来标记数字是否已经统计过来,数字做为key, value仅为0 or1,那么这样需要消耗 ...
- (转)忘记wamp-mysql数据库root用户密码重置方法
转自:http://www.jb51.net/article/28883.htm 1.打开任务管理器,结束进程 mysqld-nt.exe . 2.运行命令窗口 1)进行php服务管理器安装目录中的 ...
- POJ3104--Drying(Binary Search)
It is very hard to wash and especially to dry clothes in winter. But Jane is a very smart girl. She ...
- Naive Bayes 笔记
Naive Bayes (朴素贝叶斯) 属于监督学习算法, 它通过计算测试样本在训练样本各个分类中的概率来确定测试样本所属分类, 取最大概率为其所属分类. 优点 在数据较少的情况下仍然有效,可以处 ...
- 区间DP石子合并问题 & 四边形不等式优化
入门区间DP,第一个问题就是线性的规模小的石子合并问题 dp数组的含义是第i堆到第j堆进行合并的最优值 就是说dp[i][j]可以由dp[i][k]和dp[k+1][j]转移过来 状态转移方程 dp[ ...
- Spring Boot 2 启动时加载properties文件
每个项目从开发到测试再到上线所需要的各种环境是不同的,这就需要维护相应的配置文件,比如properties或yml文件.有了配置文件后就要考虑如何与应用进行集成. 对于云环境来讲,项目发布需要打成镜像 ...
- 一些LinuxC的小知识点(一)
以下代码在Federo9上试验成功. 一.格式化输入16进制字符串 printf(); 输入结果: 二.测试各类型的占用的字节数 int main(int argc, char *argv[]) { ...
- ADO.NET系列之事务和调用存储过程
ADO.NET系列之Connection对象 ADO.NET系列之Command对象 ADO.NET系列之DataAdapter对象 ADO.NET系列之事务和调用存储过程 前几篇我们介绍了Conne ...
- cad2020卸载/安装失败/如何彻底卸载清除干净cad2020注册表和文件的方法
cad2020提示安装未完成,某些产品无法安装该怎样解决呢?一些朋友在win7或者win10系统下安装cad2020失败提示cad2020安装未完成,某些产品无法安装,也有时候想重新安装cad2020 ...
- app绘制手势密码 、九宫格分解
什么是九宫格? 即是我们常见的手势绘制.一共有9个点,让我们进行绘制手势.我们手动操作的时候,通过是按住第一个点,然后移动到最后一点,然后松开,就完成手势的操作,那么,如果要用自动化代码,来让其自动绘 ...