es 安装ik分词器

发布于:2025-03-05 ⋅ 阅读:(17) ⋅ 点赞:(0)

下载

Index of: analysis-ik/stable/

查找对应版本下载

安装

将压缩包上传到服务器es安装路径下plugin目录,如我的安装在/usr/local下。

在plugin下新建analysis-ik文件夹,将zip文件解压到analysis-ik目录下.

修改目录及目录下所有文件的用户和用户组,chown -R /usr/local/elasticsearch

重启es

找到elasticsearch的bin文件,使用./elasticsearch启动,可以看到类似输出。

使用./elasticsearch -d代表后台启动

校验

找到elasticsearch的bin文件,使用./elasticsearch-plugin list 查看

或者在可视化客户端,执行

 索引字段设置ik分词器

注意:如果此索引已存在数据,则不能通过次方式修改分词器

PUT /esb-m-produce-logs-000029/_mapping

{

  "properties": {

    "msgContent": {

      "type": "text",

      "analyzer": "ik_max_word",

      "search_analyzer": "ik_smart"

    }

  }

}

可选方式:

1.删除并重新创建索引

如果你可以删除现有的索引并重新创建它,这是最简单的方法。请注意,这将导致所有现有数据丢失。

DELETE /your_index

PUT /your_index
{
  "settings": {
    "analysis": {
      "analyzer": {
        "ik_max_word": {
          "type": "ik_max_word"
        },
        "ik_smart": {
          "type": "ik_smart"
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "msgContent": {
        "type": "text",
        "analyzer": "ik_max_word",
        "search_analyzer": "ik_smart"
      }
    }
  }
}

2. 使用新的索引和重索引数据

如果不能删除现有索引,你可以创建一个新索引,并将数据从旧索引重索引到新索引。

PUT /new_index
{
  "settings": {
    "analysis": {
      "analyzer": {
        "ik_max_word": {
          "type": "ik_max_word"
        },
        "ik_smart": {
          "type": "ik_smart"
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "msgContent": {
        "type": "text",
        "analyzer": "ik_max_word",
        "search_analyzer": "ik_smart"
      }
    }
  }
}

POST /_reindex
{
  "source": {
    "index": "old_index"
  },
  "dest": {
    "index": "new_index"
  }
}

3. 更新映射(仅适用于某些情况)

在某些情况下,你可能能够更新映射而不会导致冲突。这通常适用于添加新的字段或更新非冲突的设置。然而,对于更改现有字段的分词器,这种方法可能不适用。

4. 使用别名(Alias)

如果你不想删除旧索引,可以使用别名来切换到新索引。首先创建新索引并重索引数据,然后将别名指向新索引。

POST /_aliases
{
  "actions": [
    { "remove": { "index": "old_index", "alias": "my_alias" }},
    { "add":    { "index": "new_index", "alias": "my_alias" }}
  ]
}


网站公告

今日签到

点亮在社区的每一天
去签到