主要知识点

1、如何建立索引

2、修改mapping

3、测试mapping

 
 

 
 

一、如何建立索引

语法

PUT /website

{

"mappings": {

"article": {

"properties": {

"author_id": {

"type": "long",

"index":"anaalyzed"

},

}

}

analyzed 分词

not_analyzed 不分词

no 不能被索引和搜索

 
 

二、修改mapping

 
 

只能创建index时手动建立mapping,或者新增field mapping,不能update field mapping(也就是不能修改已创建好的field的mapping)

 
 

1、先插入一个index

PUT /website

{

"mappings": {

"article": { #--->type

"properties": {

"author_id": { # ---->field

"type": "long"

},

"title": { # ---->field

"type": "text",

"analyzer": "english"

},

"content": { # ---->field

"type": "text"

},

"post_date": { # ---->field

"type": "date"

},

"publisher_id": { # ---->field

"type": "text",

"index": "not_analyzed"

}

}

}

}

}

 
 

2、修改已存在的field的type

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

}

3、插入新的field,并指定mapping

PUT /website/_mapping/article

{

"properties" : {

"new_field" : {

"type" : "string",

"index": "not_analyzed"

}

}

}

 
 

三、测试mapping

1、测试可分词

GET /website/_analyze

{

"field": "content",

"text": "my-dogs"

}

2、测试不可分词

GET website/_analyze

{

"field": "new_field",

"text": "my dogs"

}

执行结果是:

{

"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

}

最新文章

  1. html5 drag
  2. ubuntu set ntpdate
  3. 纯CSS3实现轮播切换效果
  4. SQL Server 查询处理中的各个阶段(SQL执行顺序)
  5. Android学习笔记之ConnectivityManager+NetWorkInfo
  6. iOS开发入门教程
  7. 《Play for Java》学习笔记(四)Controller
  8. 云主机-vps购买
  9. HDU 5750 Dertouzos 简单数学
  10. Visual Studio中的项目属性-->生成-->配置
  11. JavaWeb之cookie
  12. Javaoop 遇到的问题
  13. Windows提权与开启远程连接
  14. [Postman]创建第一个集合(2)
  15. 【jenkins git】Failed to connect to repository:Error performing command:git.exe ls-remote-h
  16. layer弹出框确定前验证:弹出消息框(弹出两个layer)
  17. 15个Spring的核心注释示例
  18. Centos7.2 修改网卡名称
  19. 关于linux 编程
  20. 好强大的页面功能调试(js调试,查找js绑定的事件)值得学习

热门文章

  1. Flume 读取JMS 消息队列消息,并将消息写入HDFS
  2. Codeforces Round #281 (Div. 2) C. Vasya and Basketball 排序
  3. ningbooj--1655--木块拼接(贪心)
  4. CentOS7 网卡名称重命名为eth*
  5. C语言程序创建文件夹
  6. 昂贵的聘礼(Dijkstra)
  7. JS 有趣的eval优化输入验证
  8. 快速搭建tab
  9. .Net并行计算支持嵌套事务的方法
  10. 图像局部显著性—点特征(GLOH)