PUT /website/article/1

{

"post_date": "2017-01-01",

"title": "my first article",

"content": "this is my first article in this website",

"author_id": 11400

}

执行上面的语句,es会创建type对应的mapping,mapping中包含了每个field对应的数据类型。

GET /website/_mapping/article

响应:

{

"website": {

"mappings": {

"article": {

"properties": {

"author_id": {

"type": "long"

},

"content": {

"type": "text",

"fields": {

"keyword": {

"type": "keyword",

"ignore_above": 256

}

}

},

"post_date": {

"type": "date"

},

"title": {

"type": "text",

"fields": {

"keyword": {

"type": "keyword",

"ignore_above": 256

}

}

}

}

}

}

}

}

1、exact value

2017-01-01,exact value,搜索的时候,必须输入2017-01-01,才能搜索出来

如果你输入一个01,是搜索不出来的

2、full text  全文检索

(1)缩写 vs. 全程:cn vs. china

(2)格式转化:like liked likes

(3)大小写:Tom vs tom

(4)同义词:like vs love

china,搜索cn,也可以将china搜索出来

likes,搜索like,也可以将likes搜索出来

Tom,搜索tom,也可以将Tom搜索出来

like,搜索love,同义词,也可以将like搜索出来

就不是说单纯的只是匹配完整的一个值,而是可以对值进行拆分词语后(分词)进行匹配,也可以通过缩写、时态、大小写、同义词等进行匹配。

3、数据类型

1、核心的数据类型

string

byte,short,integer,long

float,double

boolean

date

2、dynamic mapping

true or false --> boolean

123 --> long

123.45 --> double

2017-01-01 --> date

"hello world" --> string/text

3、查看mapping

GET /index/_mapping/type

4、如何建立索引

1、如何建立索引

analyzed

not_analyzed

no

2、修改mapping

只能创建index时手动建立mapping,或者新增field mapping,但是不能update field mapping

PUT /website

{

"mappings": {

"article": {

"properties": {

"author_id": {

"type": "long"

},

"title": {

"type": "text",

"analyzer": "english"

},

"content": {

"type": "text"

},

"post_date": {

"type": "date"

},

"publisher_id": {

"type": "text",

"index": "not_analyzed"   //not_analyzed

}

}

}

}

}

不能update field mapping

PUT /website

{

"mappings": {

"article": {

"properties": {

"author_id": {

"type": "text"

}

}

}

}

}

{

"error": {

"root_cause": [

{

"type": "index_already_exists_exception",

"reason": "index [website/co1dgJ-uTYGBEEOOL8GsQQ] already exists",

"index_uuid": "co1dgJ-uTYGBEEOOL8GsQQ",

"index": "website"

}

],

"type": "index_already_exists_exception",

"reason": "index [website/co1dgJ-uTYGBEEOOL8GsQQ] already exists",

"index_uuid": "co1dgJ-uTYGBEEOOL8GsQQ",

"index": "website"

},

"status": 400

}

//建立一个新的field并指定mapping

PUT /website/_mapping/article

{

"properties" : {

"new_field" : {

"type" :    "string",

"index":    "not_analyzed"

}

}

}

3、测试mapping

GET /website/_analyze

{

"field": "content",

"text": "my-dogs"

}

GET website/_analyze

{

"field": "new_field",

"text": "my dogs"

}

//下面报错是因为new_field不允许分词

{

"error": {

"root_cause": [

{

"type": "remote_transport_exception",

"reason": "[4onsTYV][127.0.0.1:9300][indices:admin/analyze[s]]"

}

],

"type": "illegal_argument_exception",

"reason": "Can't process field [new_field], Analysis requests are only supported on tokenized fields"

},

"status": 400

}

elasticsearch的mapping的更多相关文章

  1. elasticsearch 之mapping

    搭好elk 后,有时候会发现kibana 统计数据时,数据类型不对,这个时候就和elasticsearch的mapping有关,虽然我们可以用logstash修改传入es里的数据类型,比如 float ...

  2. curl方式创建elasticsearch的mapping

    curl方式创建elasticsearch的mapping curl -XPUT 'http://192.168.1.105:9200/bank/item2/_mapping' -d '{ " ...

  3. elasticsearch的mapping映射

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

  4. ELK学习总结(4-1)elasticsearch更改mapping(不停服务重建索引)

    elasticsearch更改mapping(不停服务重建索引)原文 http://donlianli.iteye.com/blog/1924721Elasticsearch的mapping一旦创建, ...

  5. elasticsearch更改mapping(不停服务重建索引)

    转载地址:http://donlianli.iteye.com/blog/1924721?utm_source=tuicool&utm_medium=referral Elasticsearc ...

  6. elasticsearch更改mapping,不停服务重建索引(转)

    原文:http://donlianli.iteye.com/blog/1924721?utm_source=tuicool&utm_medium=referral Elasticsearch的 ...

  7. 通过Java的Domain类构建ElasticSearch的mapping

    通过给定一个Java的class类自行创建ElasticSearch的mapping Order的domain类 public class Order { public String system_i ...

  8. elasticsearch 修改 mapping

    Elasticsearch的mapping一旦创建,只能增加字段,而不能修改已经mapping的字段.但现实往往并非如此啊,有时增加一个字段,就好像打了一个补丁,一个可以,但是越补越多,最后自己都觉得 ...

  9. ElasticSearch(5)-Mapping

    一.Mapping概述 映射 为了能够把日期字段处理成日期,把数字字段处理成数字,把字符串字段处理成全文本(Full-text)或精确的字符串值,Elasticsearch需要知道每个字段里面都包含了 ...

  10. Elasticsearch索引mapping的写入、查看与修改(转)

    mapping的写入与查看 首先创建一个索引: curl -XPOST "http://127.0.0.1:9200/productindex" {"acknowledg ...

随机推荐

  1. MS SQL 迁移数据库文件

    MS SQL 数据库迁移文件,这里说的不是将数据库迁移到另外一台服务器,只是在服务器不同磁盘目录内做迁移.移动数据库文件的情况大致有下面一些: 1: 事先没有规划好,数据库文件或日志文件增长过快,导致 ...

  2. [MySQL]--查询性能分析工具-explain关键字

    explain显示了MySQL如何使用索引来处理select语句以及连接表.可以帮助选择更好的索引和写出更优化的查询语句. explain的使用方法很简单,只需要在select查询语句前面加上expl ...

  3. ExtJs之gridPanel的属性表格,编辑表格,表格分页,分组等技巧

    这里藏的配置确实多.. 慢慢实践吧. <!DOCTYPE html> <html> <head> <title>ExtJs</title> ...

  4. Oracle中如何判断字符串是否全为数字

    Oracle中如何判断字符串是否全为数字 学习了:http://www.cnblogs.com/zrcoffee/archive/2012/12/11/2812744.html 本文介绍了判断字符串是 ...

  5. 杭电(hdu)ACM 1010 Tempter of the Bone

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  6. 面向基于英特尔&#174; 架构的 Android* 的 CoCos2D

    Cocos2D 是一款游戏引擎,可与从电脑到手机等多种设备配合使用. 该引擎支持丰富的特性,可帮助创建出色的 2D 游戏.它甚至包含具备全面功能的物理引擎. CoCos2D 的核心元素是基本动画元素( ...

  7. Codeforces444A_DZY Loves Physics

    DZY Loves Physics time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  8. maven创建web报错failure to transfer org.codehaus.plexus

    failure to transfer org.codehaus.plexus:plexus:pom:2.0.5 from http:// repo.maven.apache.org/maven2 w ...

  9. luogu2054 洗牌 同余方程

    题目大意 对于扑克牌的一次洗牌是这样定义的,将一叠N(N为偶数)张扑克牌平均分成上下两叠,取下面一叠的第一张作为新的一叠的第一张,然后取上面一叠的第一张作为新的一叠的第二张,再取下面一叠的第二张作为新 ...

  10. 让ubuntu支持GBK编码AAAAA

    Eclipse 添加GBK编码 首先Windows->Preferences, 然后选择General下面的Workspace. Text file encoding选择Other GBK, 如 ...