一、创建索引时,自定义拼音分词和ik分词

  1. PUT /my_index
  2. {
  3. "index": {
  4. "analysis": {
  5. "analyzer": {
  6. "ik_pinyin_analyzer": { 自定义分词name
  7. "type": "custom",
  8. "tokenizer": "ik_smart",
  9. "filter": ["my_pinyin", "word_delimiter"]
  10. },
  11. "pinyin_analyzer": {
  12. "type": "custom",
  13. "tokenizer": "ik_max_word",
  14. "filter": ["my_pinyin", "word_delimiter"]
  15. }
  16. },
  17. "filter": {
  18. "my_pinyin": {
  19. "type" : "pinyin",
  20. "keep_separate_first_letter" : false, 启用该选项时,将保留第一个字母分开,例如:刘德华> ldh,默认:false,注意:查询结果也许是太模糊,由于长期过频
  21. "keep_full_pinyin" : true, 当启用该选项,例如:刘德华> [ liudehua],默认值:true
  22. "keep_original" : true, 启用此选项时,也将保留原始输入,默认值:false
  23. "limit_first_letter_length" : 16, 设置first_letter结果的最大长度,默认值:16
    "lowercase" : true, 小写非中文字母,默认值:true
    "remove_duplicated_term" : true 启用此选项后,将删除重复的术语以保存索引,例如:de> dedefaultfalse,注意:位置相关的查询可能会受到影响
    }
    }
    }
    }
    }

二、创建mapping时,设置字段分词(注:相同索引下建不同的type时,相同字段名属性必须设一样)

  1. POST /my_index/user/_mapping
  2. {
  3. "user": {
  4. "properties": {
  5. "id":{
  6. "type":"integer"
  7. },
  8. "userName": {
  9. "type": "text",
  10. "store": "no",
  11. "term_vector": "with_positions_offsets",
  12. "analyzer": "ik_pinyin_analyzer", 自定义分词器name
  13. "boost": 10,
  14. "fielddata" : true,
  15. "fields": {
  16. "raw": {
  17. "type": "keyword" 设置keyword时,对该字段不进行分析
  18. }
  19. }
  20. },
  21. "reason":{
  22. "type": "text",
  23. "store": "no", 字段storetrue,这意味着这个field的数据将会被单独存储。这时候,如果你要求返回field1storeyes),es会分辨出field1已经被存储了,因此不会从_source中加载,而是从field1的存储块中加载。
  24. "term_vector": "with_positions_offsets",
  25. "analyzer": "ik_pinyin_analyzer",
  26. "boost": 10
  27. }
  28. }
  29. }
  30. }

测试

  1. PUT /my_index/user/1
  2. {
  3. "id":1,
  4. "userName":"刘德华",
  5. "reason":"大帅哥"
  6. }
  7.  
  8. PUT /my_index/user/2
  9. {
  10. "id":2,
  11. "userName":"刘德华",
  12. "reason":"中华人民"
  13. }

不分词查询

  1. GET /my_index/user/_search
  2. {
  3. "query": {
  4. "match": {
  5. "userName.raw": "刘德华"
  6. }
  7. }
  8. }
  9.  
  10. {
  11. "took": 0,
  12. "timed_out": false,
  13. "_shards": {
  14. "total": 5,
  15. "successful": 5,
  16. "skipped": 0,
  17. "failed": 0
  18. },
  19. "hits": {
  20. "total": 2,
  21. "max_score": 0.2876821,
  22. "hits": [
  23. {
  24. "_index": "my_index",
  25. "_type": "user",
  26. "_id": "2",
  27. "_score": 0.2876821,
  28. "_source": {
  29. "id": 2,
  30. "userName": "刘德华",
  31. "reason": "中华人民"
  32. }
  33. },
  34. {
  35. "_index": "my_index",
  36. "_type": "user",
  37. "_id": "1",
  38. "_score": 0.2876821,
  39. "_source": {
  40. "id": 1,
  41. "userName": "刘德华",
  42. "reason": "大帅哥"
  43. }
  44. }
  45. ]
  46. }
  47. }

分词查询

  1. GET /my_index/user/_search
  2. {
  3. "query": {
  4. "match": {
  5. "userName": "刘"
  6. }
  7. }
  8. }
  9.  
  10. {
  11. "took": 0,
  12. "timed_out": false,
  13. "_shards": {
  14. "total": 5,
  15. "successful": 5,
  16. "skipped": 0,
  17. "failed": 0
  18. },
  19. "hits": {
  20. "total": 2,
  21. "max_score": 0.31331712,
  22. "hits": [
  23. {
  24. "_index": "my_index",
  25. "_type": "user",
  26. "_id": "2",
  27. "_score": 0.31331712,
  28. "_source": {
  29. "id": 2,
  30. "userName": "刘德华",
  31. "reason": "中华人民"
  32. }
  33. },
  34. {
  35. "_index": "my_index",
  36. "_type": "user",
  37. "_id": "1",
  38. "_score": 0.31331712,
  39. "_source": {
  40. "id": 1,
  41. "userName": "刘德华",
  42. "reason": "大帅哥"
  43. }
  44. }
  45. ]
  46. }
  47. }

拼音分词

  1. GET /my_index/user/_search
  2. {
  3. "query": {
  4. "match": {
  5. "reason": "shuai"
  6. }
  7. }
  8. }
  9.  
  10. {
  11. "took": 0,
  12. "timed_out": false,
  13. "_shards": {
  14. "total": 5,
  15. "successful": 5,
  16. "skipped": 0,
  17. "failed": 0
  18. },
  19. "hits": {
  20. "total": 1,
  21. "max_score": 3.4884284,
  22. "hits": [
  23. {
  24. "_index": "my_index",
  25. "_type": "user",
  26. "_id": "1",
  27. "_score": 3.4884284,
  28. "_source": {
  29. "id": 1,
  30. "userName": "刘德华",
  31. "reason": "大帅哥"
  32. }
  33. }
  34. ]
  35. }
  36. }

分组聚合

  1. GET /my_index/user/_search
  2. {
  3. "size":2,
  4. "query": {
  5. "match": {
  6. "userName": "liu"
  7. }
  8. },
  9. "aggs": {
  10. "group_by_meetingType": {
  11. "terms": {
  12. "field": "userName.raw"
  13. }
  14. }
  15. }
  16. }
  17.  
  18. {
  19. "took": 1,
  20. "timed_out": false,
  21. "_shards": {
  22. "total": 5,
  23. "successful": 5,
  24. "skipped": 0,
  25. "failed": 0
  26. },
  27. "hits": {
  28. "total": 2,
  29. "max_score": 3.133171,
  30. "hits": [
  31. {
  32. "_index": "my_index",
  33. "_type": "user",
  34. "_id": "2",
  35. "_score": 3.133171,
  36. "_source": {
  37. "id": 2,
  38. "userName": "刘德华",
  39. "reason": "中华人民"
  40. }
  41. },
  42. {
  43. "_index": "my_index",
  44. "_type": "user",
  45. "_id": "1",
  46. "_score": 3.133171,
  47. "_source": {
  48. "id": 1,
  49. "userName": "刘德华",
  50. "reason": "大帅哥"
  51. }
  52. }
  53. ]
  54. },
  55. "aggregations": {
  56. "group_by_meetingType": {
  57. "doc_count_error_upper_bound": 0,
  58. "sum_other_doc_count": 0,
  59. "buckets": [
  60. {
  61. "key": "刘德华",
  62. "doc_count": 2
  63. }
  64. ]
  65. }
  66. }
  67. }

大神们这些都是个人理解哪里有一样的想法或建议欢迎评论!!!!!!!

Elasticsearch拼音和ik分词器的结合应用的更多相关文章

  1. Elasticsearch下安装ik分词器

    安装ik分词器(必须安装maven) 上传相应jar包 解压到相应目录 unzip elasticsearch-analysis-ik-master.zip(zip包) cp -r elasticse ...

  2. 【ELK】【docker】【elasticsearch】2.使用elasticSearch+kibana+logstash+ik分词器+pinyin分词器+繁简体转化分词器 6.5.4 启动 ELK+logstash概念描述

    官网地址:https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html#docker-cli-run-prod ...

  3. Elasticsearch 7.x - IK分词器插件(ik_smart,ik_max_word)

    一.安装IK分词器 Elasticsearch也需要安装IK分析器以实现对中文更好的分词支持. 去Github下载最新版elasticsearch-ik https://github.com/medc ...

  4. linux(centos 7)下安装elasticsearch 5 的 IK 分词器

    (一)到IK 下载 对应的版本(直接下载release版本,避免mvn打包),下载后是一个zip压缩包 (二)将压缩包上传至elasticsearch 的安装目录下的plugins下,进行解压,运行如 ...

  5. 通过docker安装elasticsearch和安装ik分词器插件及安装kibana

    前提: 已经安装好docker运行环境: 步骤: 1.安装elasticsearch 6.2.2版本,目前最新版是7.2.0,这里之所以选择6.2.2是因为最新的SpringBoot2.1.6默认支持 ...

  6. 【ELK】【docker】【elasticsearch】1. 使用Docker和Elasticsearch+ kibana 5.6.9 搭建全文本搜索引擎应用 集群,安装ik分词器

    系列文章:[建议从第二章开始] [ELK][docker][elasticsearch]1. 使用Docker和Elasticsearch+ kibana 5.6.9 搭建全文本搜索引擎应用 集群,安 ...

  7. docker 部署 elasticsearch + elasticsearch-head + elasticsearch-head跨域问题 + IK分词器

    0.  docker pull 拉取elasticsearch + elasticsearch-head 镜像 1.  启动elasticsearch Docker镜像 docker run -di ...

  8. Docker 下Elasticsearch 的安装 和ik分词器

    (1)docker镜像下载 docker pull elasticsearch:5.6.8 (2)安装es容器 docker run -di --name=changgou_elasticsearch ...

  9. Elasticsearch(ES)分词器的那些事儿

    1. 概述 分词器是Elasticsearch中很重要的一个组件,用来将一段文本分析成一个一个的词,Elasticsearch再根据这些词去做倒排索引. 今天我们就来聊聊分词器的相关知识. 2. 内置 ...

随机推荐

  1. Golang中的自动伸缩和自防御设计

    Raygun服务由许多活动组件构成,每个组件用于特定的任务.其中一个模块是用Golang编写的,负责对iOS崩溃报告进行处理.简而言之,它接受本机iOS崩溃报告,查找相关的dSYM文件,并生成开发者可 ...

  2. Redis实现世界杯排行榜功能(实战)

    转载请注明出处:https://www.cnblogs.com/wenjunwei/p/9754346.html 需求 前段时间,做了一个世界杯竞猜积分排行榜.对世界杯64场球赛胜负平进行猜测,猜对+ ...

  3. 解读经典《C#高级编程》第七版 Page38-45.核心C#.Chapter2

    前言 控制流是语言中最基础的部分,我们不谈具体的细节,只讲讲一些关键和有趣的点. 01 流控制 条件语句:if, else if, else if语句的使用非常值得细讲,如何是好的使用习惯.有一点非常 ...

  4. MDK 中 [WEAK] 的作用

    简介 __weak 或 [weak] 具有相同的功能,用于定义变量或者函数,常见于定义函数,在 MDK 链接时优先链接定义为非 weak 的函数或变量,如果找不到则再链接 weak 函数. 在STM3 ...

  5. React Fiber源码分析 第一篇

    先附上流程图一张 先由babel编译, 调用reactDOM.render,入参为element, container, callback, 打印出来可以看到element,container,cal ...

  6. [转]Node.js中koa使用redis数据库

    本文转自:https://blog.csdn.net/offbye/article/details/52452322 Redis是一个常用的Nosql数据库,一般用来代替Memcached做缓存服务, ...

  7. 【转载】Sqlserver强制密码过期导致数据库登录失败

    Sqlserver在设置登录账户信息的时候,有个复选框信息会被默认勾上,即强制实施密码策略,默认勾选上的还有强制密码过期.如果勾上了这个强制密码过期后,则你的账户密码在一定时间登录后会提示Sqlser ...

  8. Asp.net连接数据库的配置方法

    1.Sqlserver数据库连接 <connectionStrings> <add name="Conn" connectionString="serv ...

  9. Intellij idea 项目目录设置 与包的显示创建

    1.把目录设置成为层级结构显示.和eclipse类似 去掉flatten Packages前面的勾 在项目中创建多级包的时候要注意,必须在Java下建,并且要全输入才能识别

  10. H5 video播放视频遇到的问题

    我在别的网站上下载了一个mp4格式的视频,加到video标签里可以正常播放, 然后我用FLV自己转成mp4,却提示不支持的格式和mine类型, 后来找到一篇文章 http://jingyan.baid ...