主要知识点

初步了解mapping

 
 

一,准备数据

插入几条数据,让es自动为我们建立一个索引

 
 

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

}

 
 

PUT /website/article/2

{

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

"title": "my second article",

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

"author_id": 11400

}

 
 

PUT /website/article/3

{

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

"title": "my third article",

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

"author_id": 11400

}

 
 

二、尝试各种搜索,并比较搜索结果

GET /website/article/_search?q=2017                         3条结果

GET /website/article/_search?q=2017-01-01          3条结果

GET /website/article/_search?q=post_date:2017-01-01         1条结果

GET /website/article/_search?q=post_date:2017         1条结果

 
 

三,查看type的mapping

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

}

}

}

}

}

}

}

}

由上结果可以看到es已自动为这个index下的type建立的mapping。es自动或程序员手动为index中的type建立的一种数据结构及其相关配置,简称为mapping。mapping分两种:

1、dynamic mapping,自动为我们建立index,创建type,以及type对应的mapping,mapping中包含了每个field对应的数据类型,以及如何分词等设置

2、手动建立的mapping,也可以手动在创建数据之前,先创建index和type,以及type对应的mapping。

 
 

四、搜索结果为什么不一致

因为es自动建立mapping的时候,为不同的field设置了不同的data type。不同的data type的分词、搜索等行为是不一样的。所以出现了_all field和post_date field的搜索表现完全不一样。

38.mapping小例子的更多相关文章

  1. Spring和Hibernate结合的一个小例子

    1.新建一个SpringHibernate的maven项目 2.pom文件的依赖为 <dependency> <groupId>junit</groupId> &l ...

  2. 基于vue-cli、elementUI的Vue超简单入门小例子

    - 这个例子还是比较简单的,独立完成后,能大概知道vue是干嘛的,可以写个todoList的小例子. - 开始写例子之前,先对环境的部署做点简单的介绍,其实和Vue官方的差不多. #如若没有安装过vu ...

  3. appium webdriver 基本操作及小例子等

    #encoding=utf-8 ''' ''' #driver新建 driver=webdriver.Remote('http://localhost:4723/wd/hub',caps) #关闭dr ...

  4. springmvc入门的第一个小例子

    今天我们探讨一下springmvc,由于是初学,所以简单的了解一下 springmvc的流程,后续会持续更新... 由一个小例子来简单的了解一下 springmvc springmvc是spring框 ...

  5. java即时通信小例子

    学习java一段时间了,今天写来一个即时通信的小例子练手在其过程中也学到了一些知识拿出来和大家分享,请路过的各位大神多多赐教... 好了下面讲一下基本的思路: 首先,编写服务器端的程序,简单点说吧就是 ...

  6. Runtime的几个小例子(含Demo)

    一.什么是runtime(也就是所谓的“运行时”,因为是在运行时实现的.)           1.runtime是一套底层的c语言API(包括很多强大实用的c语言类型,c语言函数);  [runti ...

  7. bootstrap 模态 modal 小例子

    bootstrap 模态 modal  小例子 <html> <head> <meta charset="utf-8" /> <title ...

  8. INI配置文件分析小例子

    随手写个解析INI配置字符串的小例子 带测试 #include <iostream> #include <map> #include <string> #inclu ...

  9. JavaScript小例子:复选框全选

    JavaScript小例子:复选框全选 这只是一个小例子,很简单,但是这个功能还是很常用的: 实现后效果如图: JavaScript代码: <script type="text/jav ...

随机推荐

  1. 最新版本号cocos2d&#173;2.0&#173;x&#173;2.0.2使用新资源载入策略!不再沿用-hd、-

     前段时间cocos2dx更新了最新版本号cocos2d­2.0­x­2.0.2.也从这个版本号開始对于资源载入与管理都改变了策略. 在之前的载入方式都是通过沿用与cocos2d-iphone一样 ...

  2. 南昌互联网行业协会筹办者祝真和华罡团队-2014年12月江西IDC排行榜

     他出自军营,拥有一身正气. 他在南昌创业,立意卓越. 从站点開始.到微营销.到线上教育,全面开花. 他在朋友圈看到不对的内容,就会即时批评. 他对朋友,又是很的和蔼可亲. 他就是南昌华罡网络创办 ...

  3. 从零開始学Xamarin.Forms(二) 环境搭建、创建项目

    一.环境搭建 Windows下环境搭建:     1.下载并安装jdk.Android SDK和NDK.当然还须要 VS2013 update 2(VS2010.VS2012均可)以上. a.  最新 ...

  4. jxl 导入导出Excel(有模板)

    1.导入 @Override public String importBusinessScope(File file, String unit_id) throws Exception { Workb ...

  5. 转:Java阳历转农历

    package cloud.app.prod.home.utils; import java.text.ParseException; import java.text.SimpleDateForma ...

  6. MTK camera 闪光灯Flashlight驱动调试流程

    MTK camera 闪光灯Flashlight驱动调试流程 分类: MtkDev  |  作者: topicdev 相关  |  发布日期 : 2014-09-26  |  热度 : 153°   ...

  7. 窗口函数 SELECT - OVER Clause (Transact-SQL)

    https://docs.microsoft.com/en-us/sql/t-sql/queries/select-over-clause-transact-sql Determines the pa ...

  8. 【BZOJ 3942】 Censoring

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=3942 [算法] 栈 + KMP [代码] #include<bits/stdc ...

  9. bzoj4373 算术天才⑨与等差数列——线段树+set

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4373 一个区间有以 k 为公差的数列,有3个条件: 1.区间 mx - mn = (r-l) ...

  10. 5.27 sorm图