首先看来创建一个mapping 来show show:

curl -XPUT "master:9200/zebra_info?pretty" -H 'Content-Type: application/json' -d'
{
"settings": {
"number_of_shards":5,
"number_of_replicas":1
},
"mappings": {
"zebra_info": {
"properties": {
"name" : {"type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_max_word", "fielddata": true, "fields": {"raw": {"type":"keyword"}}},
"firstly_classification": {"type": "keyword"},
"secondary_classification": {"type": "keyword"},
"type_name": {"type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_max_word", "fielddata": true,"fields": {"raw": {"type":"keyword"}}},
"province": {"type": "keyword"},
"city": {"type": "keyword"},
"citycode": {"type": "keyword"},
"district": {"type": "keyword"},
"adcode": {"type": "keyword"},
"township": {"type": "text"},
"business_circle": {"type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_max_word", "fielddata": true,"fields": {"raw": {"type":"keyword"}}},
"formatted_address": {"type": "text"},
"location": {"type": "geo_point"},
"extensions": {
"type": "nested",
"properties": {
"avg_price": {"type": "double"},
"shops": {"type":"integer"},
"good_comments": {"type":"byte"},
"lvl": {"type":"byte"},
"other_type": {"type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_max_word", "fielddata": true, "fields": {"raw": {"type":"keyword"}}},
"numbers": {"type": "integer"}
}
}
}
}
}
}
'

二、show 看过了,来看一下elasticsearch 支持的数据类型。


1,text:
当一个字段是要被全文搜索的,比如Email内容、产品描述,应该使用text类型。设置text类型以后,字段内容会被分析,在生成倒排索引以前,字符串会被分析器分成一个一个词项。text类型的字段不用于排序,很少用于聚合(termsAggregation除外)。
如果要聚合,请设置成keyword 参照上面的索引,设置一个fielddata。 聚合或者排序的时候用name.raw 进行排序。
"name" : {"type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_max_word", "fielddata": true, "fields": {"raw": {"type":"keyword"}}} 2,keyword:
keyword类型适用于索引结构化的字段,比如email地址、主机名、状态码和标签。如果字段需要进行过滤(比如查找已发布博客中status属性为published的文章)、排序、聚合。keyword类型的字段只能通过精确值搜索到。 3,数据类型 范围
long -2^63至2^63-1
integer -2^31至2^31-1
short -32,768至32768
byte -128至127
double 64位双精度IEEE 754浮点类型
float 32位单精度IEEE 754浮点类型
half_float 16位半精度IEEE 754浮点类型
scaled_float 缩放类型的的浮点数(比如价格只需要精确到分,price为57.34的字段缩放因子为100,存起来就是5734)相当于可以定义精确度
用法如下:
PUT my_index
{
"mappings": {
"my_type": {
"properties": {
"number_of_bytes": {
"type": "integer"
},
"time_in_seconds": {
"type": "float"
},
"price": {
"type": "scaled_float",
"scaling_factor": 100
}
}
}
}
} 4,object 类型 或者说是嵌套类型。定义参见文章标题给出的索引
PUT my_index/my_type/1
{
"region": "US",
"manager": {
"age": 30,
"name": {
"first": "John",
"last": "Smith"
}
}
} 5, 日期类型
支持的格式如下:
日期格式的字符串:e.g. “2015-01-01” or “2015/01/01 12:10:30”.
long类型的毫秒数( milliseconds-since-the-epoch)
integer的秒数(seconds-since-the-epoch)
举栗子如下:
PUT my_index/my_type/1
{ "date": "2015-01-01" }
PUT my_index/my_type/2
{ "date": "2015-01-01T12:10:30Z" }
PUT my_index/my_type/3
{ "date": 1420070400001 } 6,Array类型
ELasticsearch没有专用的数组类型,默认情况下任何字段都可以包含一个或者多个值,但是一个数组中的值要是同一种类型。例如:
字符数组: [ “one”, “two” ]
整型数组:[1,3]
嵌套数组:[1,[2,3]],等价于[1,2,3]
对象数组:[ { “name”: “Mary”, “age”: 12 }, { “name”: “John”, “age”: 10 }]
注意事项:
动态添加数据时,数组的第一个值的类型决定整个数组的类型
混合数组类型是不支持的,比如:[1,”abc”]
数组可以包含null值,空数组[ ]会被当做missing field对待。 7,geo 类型,可以是点,线,或者面(区域)
地理位置信息类型用于存储地理位置信息的经纬度。 8,其他不常用的类型。
range 类型
integer_range -2^31至2^31-1
float_range 32-bit IEEE 754
long_range -2^63至2^63-1
double_range 64-bit IEEE 754
date_range 64位整数,毫秒计时 ip 类型,binary 类型,token_count 类型, nested类型类型(特殊的object 类型)

elasticsearch 5.x 系列之三 mapping 映射的时候的各个字段的设置的更多相关文章

  1. Elasticsearch学习系列之mapping映射

    什么是映射 为了能够把日期字段处理成日期,把数字字段处理成数字,把字符串字段处理成全文本(Full-text)或精确(Exact-value)的字符串值,Elasticsearch需要知道每个字段里面 ...

  2. 剖析Elasticsearch集群系列之三:近实时搜索、深层分页问题和搜索相关性权衡之道

    转载:http://www.infoq.com/cn/articles/anatomy-of-an-elasticsearch-cluster-part03 近实时搜索 虽然Elasticsearch ...

  3. spice在桌面虚拟化中的应用系列之三(USB映射实现,SSL加密,密码认证,多客户端支持)

    本系列其它文章 spice在桌面虚拟化中的应用系列之一(spice简介,性能优化等) spice在桌面虚拟化中的应用系列之二(Linux平台spice客户端的编译安装,支持USB映射) 1.spice ...

  4. elasticsearch的mapping映射

    Mapping简述 Elasticsearch是一个schema-less的系统,但并不代表no shema,而是会尽量根据JSON源数据的基础类型猜测你想要的字段类型映射.Elasticsearch ...

  5. elasticsearch中的mapping映射配置与查询典型案例

    elasticsearch中的mapping映射配置与查询典型案例 elasticsearch中的mapping映射配置示例比如要搭建个中文新闻信息的搜索引擎,新闻有"标题".&q ...

  6. 第三百六十四节,Python分布式爬虫打造搜索引擎Scrapy精讲—elasticsearch(搜索引擎)的mapping映射管理

    第三百六十四节,Python分布式爬虫打造搜索引擎Scrapy精讲—elasticsearch(搜索引擎)的mapping映射管理 1.映射(mapping)介绍 映射:创建索引的时候,可以预先定义字 ...

  7. elasticsearch 5.6.4自动创建索引与mapping映射关系 +Java语言

    由于业务上的需求 ,最近在研究elasticsearch的相关知识 ,在网上查略了大部分资料 ,基本上对elasticsearch的数据增删改都没有太大问题 ,这里就不做总结了  .但是,在网上始终没 ...

  8. Elasticsearch(八)【NEST高级客户端--Mapping映射】

    要使用NEST与Elasticsearch进行交互,我们需要能够将我们的解决方案中的POCO类型映射到存储在Elasticsearch中的反向索引中的JSON文档和字段.本节介绍NEST中可用的所有不 ...

  9. 四十三 Python分布式爬虫打造搜索引擎Scrapy精讲—elasticsearch(搜索引擎)的mapping映射管理

    1.映射(mapping)介绍 映射:创建索引的时候,可以预先定义字段的类型以及相关属性elasticsearch会根据json源数据的基础类型猜测你想要的字段映射,将输入的数据转换成可搜索的索引项, ...

随机推荐

  1. input type=number去掉上下箭头

    <input type="number" ...> <style> input::-webkit-outer-spin-button, input::-we ...

  2. 【Leetcode】【Easy】Merge Sorted Array

    Given two sorted integer arrays A and B, merge B into A as one sorted array. Note:You may assume tha ...

  3. Qt socket制作一个简单的文件传输系统

    服务器 用qt designer设计出服务器界面: 上代码: Server.pro #------------------------------------------------- # # Pro ...

  4. OpenGL总结

    最近2D转向3D,也从固定管线转到了可编程管线,有些细节的东西记录一下. Geometry Shader Geometry Shader从Vertex Shader中获取数据,向Fragment Sh ...

  5. libxml2库函数详解

    许多事物符合80/20法则,libxml中也是20%的函数提供了80%的功能.下面的列表列出了libxml的主要函数及其用法说明. 1.   全局函数说明 头文件引用 xml2config --cfl ...

  6. 在Hibernate单向一对多关联关系中的org.hibernate.StaleStateException 异常。

    具体异常如下: Caused by: org.hibernate.StaleStateException: Batch update returned unexpected row count fro ...

  7. 广义mandelbrot集,使用python的matplotlib绘制,支持放大缩小

    迭代公式的指数,使用的1+5j,这是个复数.所以是广义mandelbrot集,大家能够自行改动指数,得到其它图形.各种库安装不全的,自行想办法,能够在这个站点找到差点儿全部的python库 http: ...

  8. 2018.10.17 学习如何使用Shiro

    参考学习https://www.javazhiyin.com/19502.html

  9. mybatis学习记录三——SqlMapConfig.xml相关参数详解

      5       SqlMapConfig.xml mybatis的全局配置文件SqlMapConfig.xml,配置内容如下: properties(属性) settings(全局配置参数) ty ...

  10. PAT 1063. Set Similarity

    1063. Set Similarity 题目大意 给定 n 个集合, k 个询问, 求任意两个集合的并集和合集. 思路 一道裸的考察 STL 中 set 的题, 我居然还用 hash 错过一遍, 用 ...