elasticsearch数据组织结构
elasticsearch数据组织结构
1. mapping
1.1. 简介
mapping:意为映射关系,特别是指组织结构。在此语境中可理解为数据结构,包括表结构,表约束,数据类型等。(非母语环境伤不起。。。晦涩无比,半小时才转过圈来)
1.2. mapping type
每个索引都有一个映射类型,它决定文档索引的方式。
映射类型分为两种:
- 元字段:_index,_type,_id,_source
- 值字段或属性:
值字段数据类型—相当于mysql的数据类型
有text,keywork,date,boolean,object,nested,geo_point等
具体见其它文档。
1.3. 映射约束
在一个索引中定义太多的字段可能会导致内存溢出,它并不像想象的那么少见。
有一些设置用来约束
index.mapping.total_fields.limit
索引字段数量,计数包括字段,对象映射,字段别名。默认值1000
index.mapping.depth.limit
字段最大深度,指对象引用的深度。默认为20.
index.mapping.nested_fields.limit
The maximum number of distinct nested mappings in an index, defaults to 50.
非重复的嵌套映射数量,默认50
index.mapping.nested_objects.limit
单一文档嵌套json对象的最大值,默认10000
index.mapping.field_name_length.limit
字段名的长度限制,默认无限制。
1.4. 动态映射
字段和映射类型无需提前定义。添加时会自动创建。
在顶层映射、内部对象及nested字段上都会如此。
1.5. 显示映射explicit mapping
设置命令语法:
PUT /<index>/_mapping
创建index并指定映射
curl -X PUT "localhost:9200/my-index?pretty" -H 'Content-Type: application/json' -d'
{
"mappings": {
"properties": {
"age": { "type": "integer" },
"email": { "type": "keyword" },
"name": { "type": "text" }
}
}
}
'
为一个映射添加字段
案例:
curl -X PUT "localhost:9200/my-index/_mapping?pretty" -H 'Content-Type: application/json' -d'
{
"properties": {
"employee-id": { # 字段名
"type": "keyword", # 字段类型
"index": false # 代表此字段不参与index
}
}
}
注意:
已存在的映射是不能修改的,下述项例外:
- 为object字段添加属性
- ignore_above的值是可以改的。
修改已存在的映射会使已有索引数据失效。如果想修改映组织关系,创建新的index并reindex数据。如果只是想修改字段名,建议添加别名字段。
1.6. 相关命令
查看索引的映射
GET /my-index/_mapping
rv = es.indices.get_mapping(index_name)
1.7. 注意事项
_doc问题
7.X及以后版本并没有type参数,但在7.x中部分命令的type位置需要写成_doc。
2. field datatypes
Elasticsearch supports a number of different datatypes for the fields in a document:
-----Core datatypes
2.1. string
text and keyword
2.1.1. text
它会被解析为individual terms before being indexed.
2.1.2. keyword
用于索引结构化内容的字段,例如email addresses, hostnames, status code.
案例
PUT my_index
{
"mappings": {
"properties": {
"tags": {
"type": "keyword"
}
}
}
}
2.2. Numeric
long, integer, short, byte, double, float, half_float, scaled_float
2.3. Date
date
2.4. Date nanoseconds
date_nanos
2.5. Boolean
boolean
2.6. Binary
binary
2.7. Range
integer_range, float_range, long_range, double_range, date_range
------Complex datatypes
2.8. Object
object for single JSON objects
2.9. Nested
nested for arrays of JSON objects
3. meta-field元字段
每个文档都有自己的元字段。
3.1. identity meta-fields
_index
_type
_id
3.2. document source meta-fields
_source:源JSON数据
_size:_source的大小,单位bytes,provided by the mapper-size plugin.
3.3. indexing meta-fields
_fields_names
_igonred
3.4. routing meta-field
_routing
3.5. other meta-field
_meta
4. analyzer
document: https://www.elastic.co/guide/en/elasticsearch/reference/current/analyzer.html
下面是一个设置索引分词器参数及应用的案例:
PUT my_index
{
"settings":{
"analysis":{
"analyzer":{
"my_analyzer":{
"type":"custom",
"tokenizer":"standard",
"filter":[
"lowercase"
]
},
"my_stop_analyzer":{
"type":"custom",
"tokenizer":"standard",
"filter":[
"lowercase",
"english_stop"
]
}
},
"filter":{
"english_stop":{
"type":"stop",
"stopwords":"_english_"
}
}
}
},
"mappings":{
"properties":{
"title": {
"type":"text",
"analyzer":"my_analyzer",
"search_analyzer":"my_stop_analyzer",
"search_quote_analyzer":"my_analyzer"
}
}
}
}
PUT my_index/_doc/1
{
"title":"The Quick Brown Fox"
}
PUT my_index/_doc/2
{
"title":"A Quick Brown Fox"
}
GET my_index/_search
{
"query":{
"query_string":{
"query":"\"the quick brown fox\""
}
}
}
elasticsearch数据组织结构的更多相关文章
- 【原创】大叔经验分享(26)hive通过外部表读写elasticsearch数据
hive通过外部表读写elasticsearch数据,和读写hbase数据差不多,差别是需要下载elasticsearch-hadoop-hive-6.6.2.jar,然后使用其中的EsStorage ...
- Oracle和Elasticsearch数据同步
Python编写Oracle和Elasticsearch数据同步脚本 标签: elasticsearchoraclecx_Oraclepython数据同步 Python知识库 一.版本 Pyth ...
- elasticsearch数据备份还原
elasticsearch数据备份还原 1.在浏览器中运行http://XXX.XXX.XXX.XXX:9200/_flush,确保索引数据能保存到硬盘中. 2.原数据的备份.主要是elasticse ...
- 18-10-15 服务器删除数据的方法【Elasticsearch 数据删除 (delete_by_query 插件安装使用)】方法二没有成功
rpa 都是5.xx ueba 分为2.0 或者5.0 上海吴工删除数据的方法 在许多项目中,用户提供的数据存储盘大小有限,在运行一段时间后,大小不够就需要删除历史的 Elasticsearch 数 ...
- [转] [Elasticsearch] 数据建模 - 处理关联关系(1)
[Elasticsearch] 数据建模 - 处理关联关系(1) 标签: 建模elasticsearch搜索搜索引擎 2015-08-16 23:55 6958人阅读 评论(0) 收藏 举报 分类: ...
- 服务追踪数据使用 RabbitMQ 进行采集 + 数据存储使用 Elasticsearch + 数据展示使用 Kibana
服务追踪数据使用 RabbitMQ 进行采集 + 数据存储使用 Elasticsearch + 数据展示使用 Kibana https://www.cnblogs.com/xishuai/p/elk- ...
- 【原创】MapReduce备份Elasticsearch数据到HDFS(JAVA)
一.环境:JAVA8,Elasticsearch-5.6.2,Hadoop-2.8.1二.实现功能:mapreduce读elasticsearch数据.输出parquet文件.多输出路径三.主要依赖 ...
- 大数据学习[16]--使用scroll实现Elasticsearch数据遍历和深度分页[转]
题目:使用scroll实现Elasticsearch数据遍历和深度分页 作者:星爷 出处: http://lxWei.github.io/posts/%E4%BD%BF%E7%94%A8scroll% ...
- 基于 MySQL Binlog 的 Elasticsearch 数据同步实践 原
一.背景 随着马蜂窝的逐渐发展,我们的业务数据越来越多,单纯使用 MySQL 已经不能满足我们的数据查询需求,例如对于商品.订单等数据的多维度检索. 使用 Elasticsearch 存储业务数据可以 ...
随机推荐
- index unique scan 与index range scan等的区别
存取Oracle当中扫描数据的方法(一) Oracle 是一个面向Internet计算环境的数据库.它是在数据库领域一直处于领先地位的甲骨文公司的产品.可以说Oracle关系数据库系统是目前世界上流行 ...
- Vue的响应式原理---(v-model中的双向绑定原理)
Vue响应式原理 不要认为数据发生改变,界面跟着更新是理所当然. 具体代码实现:https://gitee.com/ahaMOMO/Vue-Responsive-Principle.git 看下图: ...
- centos源码安装git最新版
到 git官网下载git 源码安装包,git官网地址:https://www.git-scm.com/ 选择Tarballs系列的安装包,官网git下载:https://mirrors.edge.ke ...
- Eqaulize Prices
There are n products in the shop. The price of the ii-th product is aiai. The owner of the shop want ...
- 使用java实现AES算法的加解密(亲测可用)
话不多说,直接上代码 import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.cryp ...
- python开发基础作业02:三级菜单,使用字典dic及列表
作业要求及提示:三级菜单 ''' 1.三级菜单 2.可依次进入各子菜单 3.菜单能够回到上一级 4.用到知识点:字典.列表.多层循环.函数 条件:基本 if else 嵌套 if...if... ...
- linux mv命令 cp命令
mv mv [options] source dest -f : 在mv操作要覆盖某已有的目标文件时不给任何指示 命令格式 运行结果 mv 文件名 文件名 将源文件名改为目标文件名 mv 文件名 目录 ...
- springboot1.5.9 整合单机版redis3.2.8
redis是一种可基于内存也可基于持久话的日志型.key-value数据库.因为性能高,存储数据类型丰富等优势常被用作数据缓存. 我们利用spring-boot-autoconfiguration.j ...
- vue 循环多个标签,点击标签变色,再点击取消,可以同时点击多个
效果: <div class="relFacilityTitcon"> <i v-for="(item,index) in facilityList&q ...
- Knapsack Cryptosystem 牛客团队赛
时限2s题意: 第一行包含两个整数,分别是n(1 <= n <= 36)和s(0 <= s <9 * 10 18) 第二行包含n个整数,它们是{a i }(0 <a i ...