38.mapping小例子

主要知识点

初步了解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的搜索表现完全不一样。

原文地址:https://www.cnblogs.com/liuqianli/p/8468572.html

时间: 2024-07-30 18:43:55

38.mapping小例子的相关文章

简述人脸特异性识别&&一个基于LBP和SVM的人脸识别小例子

原谅我用图片,MAC在Safari里给文章进行图文排版太麻烦啦~ 本文适合初入计算机视觉和模式识别方向的同学们观看~ 文章写得匆忙,加上博主所知甚少,有不妥和勘误请指出并多多包涵. 本文Demo的代码由HZK编写,特征点由月神和YK选择和训练. 转载请注明 copyleft by sciencefans, 2014 为了方便大家学习,附上高维LBP的核心代码 1 ################################################### 2 # 3 # 4 # NO

java Dom小例子

仅仅是为了总结与学习. XML文件在我们的开发项目中经常使用,下面写了DOM解析的小例子. DomTestFile.xml文件如下: <?xml version="1.0" encoding="utf-8"?> <MenuContainer> <menu order="1.0" menuname="测试1" description="描述1"> <menu orde

SpringMVC+hibernate整合小例子,用户的增删查改

SpringMVC+hibernate整合小例子,用户的增删查改 对于使用框架写项目,我的第一反应的把所有需要的jar文件引入. 因为我用的是JDK1.8,当使用spring3.2 注解的时候会出现问题,所以最终使用的spring4.0.  hibernate使用的版本为4.0 .至于一些依赖包的版本就是看别人的资料拿的. 然后看下整体的项目结构 第一步写的是web.xml配置文件,当然有写东西是后面加上去的,不是一步到位的,比如说控制post方式的乱码.以及无法时候JS文件等一些静态文件,后面

js小例子(标签页)

运用js写的一个小例子,实现点击不同的标签出现不同的内容: 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta chaset="utf-8"> 5 <script> 6 function nav(obj, x) 7 { 8 var a = obj.parentNode.parentNode.children; 9 for(var i =0;i<a.length;i++) { 10 a[

JS模拟键盘事件 -- 原理及小例子

小例子: (Chrome下可用,其他浏览器未测试,使用新方法,暂不考虑兼容性) 代码如下: 1 <input type="button" tabindex="-1" value="点点点点点" id="btn"> 2 <input type="text" placeholder="1"> 3 <input type="text" plac

SpringMVC+Spring+Hibernate的小例子

Strusts2+Spring+Hibernate虽然是主流的WEB开发框架,但是SpringMVC有越来越多的人使用了,确实也非常好用,用得爽! 这里实现了一个SpringMVC+Spring+Hibernate的小例子.注释都在代码里面. 项目各包的结构如下图: 1, 首先是pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLS

JavaScript之属性操作及小例子

一.属性操作示例代码 代码详解: 首先要知道,html找标签是通过选择器,JavaScript寻找标签是通过,例: document.getElementById('box');可这么理解:在文档下寻找通过id标签获取元素 所以,下面两行代码可理解为:声明变量=后面接收通过box标签获得span区域元素,通过ul标签获得ul区域元素 var box=document.getElementById('box'); var ul=document.getElementById('ul');接下来就可

appium webdriver 基本操作及小例子等

#encoding=utf-8 ''' ''' #driver新建 driver=webdriver.Remote('http://localhost:4723/wd/hub',caps) #关闭driver driver.quit() #find_element_by_id box=driver.find_element_by_id('com.xsteach.appedu:id/rl_home_top_search') box=driver.find_element_by_id('rl_hom

laravel 数据库操作小例子

public function demo() { $res = null; //insert数据插入 //$user=array('username'=>'joy','password'=>'123456','age'=>23); //$res = DB::table('users')->insert($user); /* 数据查询 $res = DB::table('users')->where('username','joy')->get(); $res = DB: