elasticsearch数据组织结构

1.      mapping

1.1.    简介

mapping:意为映射关系,特别是指组织结构。在此语境中可理解为数据结构,包括表结构,表约束,数据类型等。(非母语环境伤不起。。。晦涩无比,半小时才转过圈来)

1.2.    mapping type

每个索引都有一个映射类型,它决定文档索引的方式。

映射类型分为两种:

  1. 元字段:_index,_type,_id,_source
  2. 值字段或属性:

值字段数据类型—相当于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

}

}

}

注意:

已存在的映射是不能修改的,下述项例外:

  1. 为object字段添加属性
  2. 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数据组织结构的更多相关文章

  1. 【原创】大叔经验分享(26)hive通过外部表读写elasticsearch数据

    hive通过外部表读写elasticsearch数据,和读写hbase数据差不多,差别是需要下载elasticsearch-hadoop-hive-6.6.2.jar,然后使用其中的EsStorage ...

  2. Oracle和Elasticsearch数据同步

    Python编写Oracle和Elasticsearch数据同步脚本 标签: elasticsearchoraclecx_Oraclepython数据同步    Python知识库 一.版本 Pyth ...

  3. elasticsearch数据备份还原

    elasticsearch数据备份还原 1.在浏览器中运行http://XXX.XXX.XXX.XXX:9200/_flush,确保索引数据能保存到硬盘中. 2.原数据的备份.主要是elasticse ...

  4. 18-10-15 服务器删除数据的方法【Elasticsearch 数据删除 (delete_by_query 插件安装使用)】方法二没有成功

    rpa 都是5.xx  ueba 分为2.0 或者5.0 上海吴工删除数据的方法 在许多项目中,用户提供的数据存储盘大小有限,在运行一段时间后,大小不够就需要删除历史的 Elasticsearch 数 ...

  5. [转] [Elasticsearch] 数据建模 - 处理关联关系(1)

    [Elasticsearch] 数据建模 - 处理关联关系(1) 标签: 建模elasticsearch搜索搜索引擎 2015-08-16 23:55 6958人阅读 评论(0) 收藏 举报 分类: ...

  6. 服务追踪数据使用 RabbitMQ 进行采集 + 数据存储使用 Elasticsearch + 数据展示使用 Kibana

    服务追踪数据使用 RabbitMQ 进行采集 + 数据存储使用 Elasticsearch + 数据展示使用 Kibana https://www.cnblogs.com/xishuai/p/elk- ...

  7. 【原创】MapReduce备份Elasticsearch数据到HDFS(JAVA)

    一.环境:JAVA8,Elasticsearch-5.6.2,Hadoop-2.8.1二.实现功能:mapreduce读elasticsearch数据.输出parquet文件.多输出路径三.主要依赖 ...

  8. 大数据学习[16]--使用scroll实现Elasticsearch数据遍历和深度分页[转]

    题目:使用scroll实现Elasticsearch数据遍历和深度分页 作者:星爷 出处: http://lxWei.github.io/posts/%E4%BD%BF%E7%94%A8scroll% ...

  9. 基于 MySQL Binlog 的 Elasticsearch 数据同步实践 原

    一.背景 随着马蜂窝的逐渐发展,我们的业务数据越来越多,单纯使用 MySQL 已经不能满足我们的数据查询需求,例如对于商品.订单等数据的多维度检索. 使用 Elasticsearch 存储业务数据可以 ...

随机推荐

  1. C++-hihoCode-1105/1109-[STL][堆][prime]

    #include <set> #include <map> #include <cmath> #include <queue> #include < ...

  2. python 操作 word 图片 消失

    问题描述修改word中文本,如下代码,保存时会导致word中的部分图片消失 from docx import Document path1 = 'test_in.docx' path2 = 'test ...

  3. 【资源分享】Gmod动态方框透视脚本

    *----------------------------------------------[下载区]----------------------------------------------* ...

  4. Unity小知识点大全(二)

    51.Inspector调试模式 在Inspector面板右上角的下拉菜单中,选择Debug命令,启动调试模式,此时将显示组件包含的所有变量,包括私有变量,当运行编辑器时,可以实时查看各组件所有变量的 ...

  5. C#中如何将字符串或者字符串数组写入文本文件

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  6. Qt入门-表格类QTableWidget

    原文 :http://blog.csdn.net/xgbing/article/details/7774737 表格是GUI中常用的控件,在Qt中,常用的表格类是QTableWidget. 示例: Q ...

  7. VS2017编写c/c++汇编函数并调用

    首先在VS里面创建个空项目,然后添加汇编文件 .asm,    右键asm文件属性  --- 常规,改成下图的设置  , 从生成中排除改为否, 项类型改为自定义生成工具 然后点确定. 再次右键asm文 ...

  8. 507,介绍一下标准的css盒子模型?低版本ie的盒子模型有什么不同的?

    有两种,IE盒子模型,另外是W3C盒子模型: 盒模型都包括:内容(content),填充(padding),边界(margin),边框(border): 区别:IE的content部分吧border和 ...

  9. Go作用域

    package main import "fmt" //全局变量的定义 //num3 := 1000//不支持简短定义的写法 var num3 = 1000 func main() ...

  10. C语言字符串类型转换为double浮点数类型

    #include <stdio.h>#include <stdlib.h>char *record; double re = atof(record); 使用 atof()函数 ...