• elastic search配置ik分词及pinyin分词使搜索同时支持中文和拼音搜索


    1、先下载ik分词和pinyin分词,并放到esplugins相应目录中

    2、定义ik分词后的pinyin分词器,即定义一个自定义分词器ik_pinyin_analyzer

    #删除索引
    DELETE common_poi
    
    #创建索引
    PUT common_poi
    {
      "settings": {
        "number_of_shards": 1,
        "number_of_replicas": 0
      }
    }
    
    #关闭索引
    POST common_poi/_close
    
    #自定义分词器(ik分器词和拼音分词)
    PUT common_poi/_settings
    {
        "settings": {
            "index": {
                "analysis": {
                    "analyzer": {
                        "ik_pinyin_analyzer": {
                            "type": "custom",
                            "tokenizer": "ik_max_word",
                            "filter": ["my_pinyin"]
                        }
                    },
                    "filter": {
                        "my_pinyin": {
                            "type": "pinyin",
                            "keep_separate_first_letter": false,
                            "keep_full_pinyin": true,
                            "keep_original": false,
                            "limit_first_letter_length": 10,
                            "lowercase": true,
                            "remove_duplicated_term": true
                        }
                    }
                }
            }
        }
    }
    
    #字段映射
    PUT common_poi/_mappings
    {
      "dynamic":false,
      "properties":{
          "id":{
              "type":"long"
          },
          "name":{
              "type":"text",
              "index":true,
              "analyzer":"ik_pinyin_analyzer"
          },
          "longitude":{
              "type":"double"
          },
          "latitude":{
              "type":"double"
          },
          "address":{
              "type":"text",
              "index":true,
              "analyzer":"ik_max_word"
          },
          "phone":{
              "type":"text",
              "index":true
          },
          "type":{
              "type":"text",
              "index":true,
              "analyzer":"ik_max_word"
          },
          "realType":{
              "type":"text",
              "index":true,
              "analyzer":"ik_max_word"
          }
      }
    }
    
    #打开索引
    POST common_poi/_open
    
    #条件搜索
    GET common_poi/_search
    {
      "query": {
        "match": {
          "name": "can饮"
        }
      }
    }
  • 相关阅读:
    IDEA 代码统计插件使用
    四种遍历ConcurrentHashMap的方式
    Java中多线程并发体系知识点汇总
    程序员高效工具列表
    js数组与字符串的相互转换方法
    ajax使用json数据格式--无效的 JSON 基元
    for和$.each 的记录
    表单提交模型记录
    /Date(1512551901709+0800)/转换
    jsonp的使用记录
  • 原文地址:https://www.cnblogs.com/haolb123/p/16553126.html
Copyright © 2020-2023  润新知