主要知识点

初步了解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. poj 3468 A Simple Problem with Integers(线段树+区间更新+区间求和)

    题目链接:id=3468http://">http://poj.org/problem? id=3468 A Simple Problem with Integers Time Lim ...

  2. 《鸟哥的Linux私房菜-基础学习篇(第三版)》(五)

    第4章 安装CentOS 5.x与多重引导小技巧        1. 本练习机的规划(尤其是分区參数)        分了四个分区: 1)/boot:primary 2)/:primary 3)/ho ...

  3. php生成随机password的几种方法

    文章来源:PHP开发学习门户 地址:http://www.phpthinking.com/archives/523 使用PHP开发应用程序,尤其是站点程序.经常须要生成随机password,如用户注冊 ...

  4. 新手对ASP.NET MVC的疑惑

    习惯了多年的WEB FORM开发方式,突然转向MVC,一下子懵了,晕头转向,好多不习惯,好多不明白,直到现在也没弄明白,只好先记下来,在应用中一一求解. 主要集中在视图(View)这里. 1.@Htm ...

  5. Android TextView 设置行间距

    Android系统中TextView默认显示中文时会比较紧凑,不是很美观.为了让每行保持一定的行间距,可以设置属性android:lineSpacingExtra或android:lineSpacin ...

  6. B - Substrings Sort

    Problem description You are given nn strings. Each string consists of lowercase English letters. Rea ...

  7. java线程中断2

    一个线程在未正常结束之前, 被强制终止是很危险的事情. 因为它可能带来完全预料不到的严重后果. 所以你看到Thread.suspend, Thread.stop等方法都被Deprecated了.那么不 ...

  8. border使用

    border属性 border-width  border-style  border-color  inherit border-style的值:none  dotted(点线)  dashed(虚 ...

  9. 金立 M6 (GN8003) 解锁 BootLoader 进入第三方 recovery 刷机 ROOT

    首先下载好工具:http://url.cn/5EILbQn 备用连接 :http://pan.baidu.com/s/1c28j7k0 本篇教程教你如何傻瓜式解锁BootLoader并刷入recove ...

  10. JavaScript变量提升及作用域

    今天在知乎看前端面试题的时候,看到这样的问题,发现自己懂的真的是太少了,看了给的例子,所以写一下自己的理解. 首先放一段代码: var v= “hello JavaScript”; alert(v); ...