• 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饮"
        }
      }
    }
  • 相关阅读:
    UOS怎么设置定时关机
    UOS如何修改源地址
    UOS如何进行全文搜索
    UOS如何查看硬盘序列号
    UOS如何修改右下角水印
    UOS怎么创建网页快捷方式
    应用商店安装软件提示uos-browser-stable错误,解决办法
    IHttpClientFactory Form 提交参数
    将.nuget文件夹移到其他盘
    windows docker 提示 bind: An attempt was made to access a socket
  • 原文地址:https://www.cnblogs.com/haolb123/p/14113086.html
Copyright © 2020-2023  润新知