Elasticsearch实战系列-mapping 设置
2017-04-01 16:08
771 查看
Elasticsearch实战系列-mapping 设置
标签: elasticsearch2016-02-29 17:49 5316人阅读 评论(0) 收藏 举报
分类:
Search(3)
版权声明:本文为博主原创文章,未经博主允许不得转载。
目录(?)[+]
本篇主要讲解Mapping的一些相关配置与需要注意的地方,说到Mapping大家可能觉得有些不解,其实我大体上可以将Elasticsearch理解为一个RDBMS(关系型数据库,比如MySQL),那么index
就相当于数据库实例,type可以理解为表,这样mapping可以理解为表的结构和相关设置的信息(当然mapping有更大范围的意思)。
默认情况不需要显式的定义mapping, 当新的type或者field引入时,Elasticsearch会自动创建并且注册有合理的默认值的mapping(毫无性能压力), 只有要覆盖默认值时才必须要提供mapping定义。
什么是Mapping
先看看官方文档中的定义A mapping defines the fields within a type, the datatype for each field, and how the field should be handled by Elasticsearch. A mapping is also used to configure metadata associated with the type.
Mapping定义了type中的诸多字段的数据类型以及这些字段如何被Elasticsearch处理,比如一个字段是否可以查询以及如何分词等。
自定义Mapping
下面是一个简单的Mapping定义:curl -XPUT 'http://localhost:9200/megacorp' -d ' { "settings": { "number_of_shards": 3, "number_of_replicas": 1 }, "mappings": { "employee": { "properties": { "first_name": { "type": "string" }, "last_name": { "type": "string" }, "age": { "type": "integer" }, "about": { "type": "string" }, "interests": { "type": "string" }, "join_time": { "type": "date", "format": "dateOptionalTime", "index": "not_analyzed" } } } } } '1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
其中employee是type(相当于关系数据库中的表),在employee中我们定义了first_name、last_name、age、about、interests、join_time这6个属性。
{ "interests": { "type": "string"}1
1
type表示field的数据类型,上例中interests的type为string表示为普通文本。
Elasticsearch支持以下数据类型:
文本: string
数字: byte, short, integer, long
浮点数: float, double
布尔值: boolean
Date: date
对于type为 string 的字段,最重要的属性是:index and analyzer。
1、index
index 属性控制string如何被索引,它有三个可选值:
analyzed: First analyze the string, then index it. In other words,
index this field as full text.
not_analyzed:: Index this field, so it is searchable, but index the
value exactly as specified. Do not analyze it.
no: Don’t index this field at all. This field will not be
searchable.
对于string类型的filed index 默认值是: analyzed.如果我们想对进行精确查找, 那么我们需要将它设置为: not_analyzed。
例如:
{ "tag": { "type": "string", "index": "not_analyzed" }1
1
2、analyzer
对于 string类型的字段, 我们可以使用 analyzer 属性来指定在搜索阶段和索引阶段使用哪个分词器. 默认, Elasticsearch 使用 standard analyzer, 你也可以指定Elasticsearch内建的其它分词器,比如 whitespace, simple, or english:
例如:
{ "tweet": { "type": "string", "analyzer": "english" }
相关文章推荐
- Elasticsearch实战系列-mapping 设置
- elasticsearch 学习博客系列<二> ES 中 index 设置 Mapping(表结构)
- elasticsearch 设置 mapping 时的 store 属性
- 实战小技巧系列(2):关于IIS6.0中应用程序池圆设置的问题
- caffe 实战系列:proto文件格式以及含义解析:如何定义网络,如何设置网络参数(以AlexNet为例)
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink高级特性与高级应用021-Flink中OutFormat设置(Scala版)001
- Elasticsearch学习系列之mapping映射
- Elasticsearch学习系列之mapping映射
- Java使用ElasticSearch API设置Mapping
- ElasticSearch优化系列二:机器设置(内存)
- Elasticsearch如何设置mapping
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink高级特性与高级应用022-Flink中OutFormat设置(Scala版)002
- Elasticsearch实战系列-环境搭建
- Elasticsearch实战系列-RESTful API使用
- elasticsearch系列-什么是Mapping
- elasticsearch的mapping设置
- Elasticsearch学习系列之mapping映射
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink高级特性与高级应用023-Flink中OutFormat设置(Scala版)003
- Elasticsearch实战系列-入门篇
- caffe 实战系列:proto文件格式以及含义解析:如何定义网络,如何设置网络参数(以AlexNet为例) 2016.3.30