阿里云ElasticSearch安装开源插件实践

本文涉及的产品
检索分析服务 Elasticsearch 版,2核4GB开发者规格 1个月
简介: 阿里云ElasticSearch安装开源插件实践,包含较为常用的NLPchina/elasticsearch-sql与medcl/elasticsearch-analysis-stconvert两个插件的安装、使用测试及同类插件的差异对比

1. 环境准备

1.1. 集群环境

阿里云ElasticSearch V6.7.0

1.2. 数据准备

1.2.1. 索引创建

PUT /products_info
{
  "mappings": {
    "products": {
      "properties": {
        "productName": {
          "type": "text",
          "analyzer": "ik_smart"
        },
        "annual_rate":{
          "type":"keyword"
        },
        "describe": {
         "type": "text",
         "analyzer": "ik_smart"
        },
        "product_age":{
          "type":"integer"
        }
      }
    }
  }
}

1.2.2. 数据导入

POST /products_info/products/_bulk
{"index":{}}
{"productName":"理财产品A","annual_rate":"3.2200%","describe":"180天定期理财,最低20000起投,收益稳定,可以自助选择消息推送","product_age":0}
{"index":{}}
{"productName":"理财产品B","annual_rate":"3.1100%","describe":"90天定投产品,最低10000起投,每天收益到账消息推送","product_age":2}
{"index":{}}
{"productName":"理财产品C","annual_rate":"3.3500%","describe":"270天定投产品,最低40000起投,每天收益立即到账消息推送","product_age":2}
{"index":{}}
{"productName":"理财产品D","annual_rate":"3.1200%","describe":"90天定投产品,最低12000起投,每天收益到账消息推送","product_age":1}
{"index":{}}
{"productName":"理财产品E","annual_rate":"3.0100%","describe":"30天定投产品推荐,最低8000起投,每天收益会消息推送","product_age":5}
{"index":{}}
{"productName":"理财产品F","annual_rate":"2.7500%","describe":"热门短期产品,3天短期,无须任何手续费用,最低500起投,通过短信提示获取收益消息","product_age":11}

1.3. 自定义/开源插件安装流程

  1. 参考阿里云官方文档:https://help.aliyun.com/zh/es/user-guide/upload-and-install-a-custom-plug-in?spm=a2c4g.11186623.0.i8
  2. 在集群详细信息配置界面依次点击如下按钮后,集群将处于生效中的变更状态,变更完成后即可使用
  1. 配置与管理
  2. 插件配置
  3. 自定义插件列表
  4. 上传
  5. 上传本地插件zip压缩包文件
  6. 上传安装

image.png

2. SQL插件

2.1. _sql summary

插件名称:NLPchina/elasticsearch-sql

参考开源地址:https://github.com/NLPchina/elasticsearch-sql/releases/tag/6.7.0.0

2.2. 使用与测试

image.png

版本不同GET请求的路径也有变更,目前我们使用的6.7.0版本需使用/_sql及/_sql/_explain

2.2.1. _sql查询

返回结果与DSL查询返回形式一致

GET _sql
{
  "sql":"select * from products_info where product_age > 0 limit 1,10"
}

image.png

2.2.2. _sql/_explain转换DSL

GET _sql/_explain
{
  "sql":"select * from products_info where product_age > 0 limit 1,10"
}
{
  "from": 1,
  "size": 10,
  "query": {
    "bool": {
      "filter": [
        {
          "bool": {
            "must": [
              {
                "range": {
                  "product_age": {
                    "from": 0,
                    "to": null,
                    "include_lower": false,
                    "include_upper": true,
                    "boost": 1.0
                  }
                }
              }
            ],
            "adjust_pure_negative": true,
            "boost": 1.0
          }
        }
      ],
      "adjust_pure_negative": true,
      "boost": 1.0
    }
  }
}

2.2.3. select tpye

在不同业务使用场景中,历史业务逻辑存在对{index}/{_type}的使用,该开源插件支持识别并查询该场景下数据

GET _sql
{
  "sql":"select * from products_info/products where product_age > 0 limit 1,10"
}

image.png

2.3. 对比aliyun-sql

参考文档:https://help.aliyun.com/zh/es/user-guide/use-the-aliyun-sql-plug-in/?spm=a2c4g.11186623.0.0.f9a81cf3eA4hMC

2.3.1. 安装与开启

aliyun-sql默认安装在阿里云ElasticSearch集群插件中,需要通过如下命令开启使用,否则会报异常:

{
  "error": {
    "root_cause": [
      {
        "type": "access_denied_exception",
        "reason": "sql plugin is disabled!"
      }
    ],
    "type": "access_denied_exception",
    "reason": "sql plugin is disabled!"
  },
  "status": 500
}
PUT _cluster/settings
{
  "transient": {
    "aliyun.sql.enabled": true
  }
}

2.3.2. _alisql查询

  1. GET请求路径不同插件有所不同,如果冲突的话需要按需卸载或者disable
  2. body请求体的key不同,_alisql为"query"
GET /_alisql
{
  "query":"select * from products_info where product_age > 0 limit 1,10"
}

image.png

2.3.3. _alisql/transalte转换DSL

GET /_alisql/translate
{
  "query":"select * from products_info where product_age > 0 limit 1,10"
}

image.png

2.3.4. 不支持/_type的用法..?

  1. 部分用户从自建/其他云厂商迁移到阿里云ElasticSearch,从_sql切换到_alisql,使用select type的语法暂不支持
GET /_alisql/translate
{
  "query":"select * from products_info/products where product_age > 0 limit 1,10"
}
{
  "error": {
    "root_cause": [
      {
        "type": "sql_parse_exception",
        "reason": "Encountered \" \"/\" \"/ \"\" at line 1, column 28.\nWas expecting:\n    <EOF> \n    "
      }
    ],
    "type": "sql_parse_exception",
    "reason": "Encountered \" \"/\" \"/ \"\" at line 1, column 28.\nWas expecting:\n    <EOF> \n    ",
    "caused_by": {
      "type": "parse_exception",
      "reason": "Encountered \" \"/\" \"/ \"\" at line 1, column 28.\nWas expecting:\n    <EOF> \n    "
    }
  },
  "status": 500
}
  1. 部分同学调整语法后发现可以正常运行,表现在替换"/"为"//"。但发现查询结果不符合预期
GET /_alisql/translate
{
  "query":"select * from products_info//products where product_age > 0 limit 1,10"
}
  1. 经过查看SQL转换成的DSL可以看出,alisql应该是将"//"视为了注释,后面的where查询,limit翻页,均没有在DSL中有所体现

image.png

  1. alisql在官网文档中查看并未开源,使用教程中也并未提到相关的语法,如有相关语句修改后正常执行的方案请各位大佬私聊指导

2.3.5. 不支持索引名中含有"-"..?

  1. 创建索引,索引名中含有"-"
PUT /products_info-1
{
  "mappings": {
    "products": {
      "properties": {
        "productName": {
          "type": "text",
          "analyzer": "ik_smart"
        },
        "annual_rate":{
          "type":"keyword"
        },
        "describe": {
         "type": "text",
         "analyzer": "ik_smart"
        },
        "product_age":{
          "type":"integer"
        }
      }
    }
  }
}
  1. 使用开源插件_sql和_alisql查询,_alisql异常如下
{
  "error": {
    "root_cause": [
      {
        "type": "sql_parse_exception",
        "reason": "Encountered \" \"-\" \"- \"\" at line 1, column 28.\nWas expecting:\n    <EOF> \n    "
      }
    ],
    "type": "sql_parse_exception",
    "reason": "Encountered \" \"-\" \"- \"\" at line 1, column 28.\nWas expecting:\n    <EOF> \n    ",
    "caused_by": {
      "type": "parse_exception",
      "reason": "Encountered \" \"-\" \"- \"\" at line 1, column 28.\nWas expecting:\n    <EOF> \n    "
    }
  },
  "status": 500
}

image.png

  1. alisql在官网文档中查看并未开源,使用教程中也并未提到相关的语法,如有相关语句修改后正常执行的方案请各位大佬私聊指导

3. 繁体/简体转换插件

3.1. summary

插件名称:medcl/elasticsearch-analysis-stconvert

参考开源地址:https://github.com/medcl/elasticsearch-analysis-stconvert/releases/tag/v6.7.0

3.2. 使用与测试

我们使用analyze的API对该analysis的插件进行使用测试。

analyze的API参考:https://www.elastic.co/guide/en/elasticsearch/reference/6.7/indices-analyze.html#indices-analyze

  1. 该插件提供的analyzer、tokenizer、filter(原:token-filter)、char-filter默认为简体转为繁体,即Traditional->Simplified
GET /_analyze
{
  "text": ["我爱北京天安门Yeah"]
  , "tokenizer": "stconvert"
}

image.png

  1. 需求为繁体转换为简体,将默认的convert_type从「s2t」修改为「t2s」,并在filter中转换为小写
GET /_analyze
{
  "text": ["我愛北京天安門Yeah"]
  ,"tokenizer": {
    "type":"stconvert"
    ,"convert_type" : "t2s"
  }
  ,"filter": ["lowercase"]
}

image.png

  1. 也可以使用指定索引analyzer的方式自定义为繁体转简体。设置convert索引的analyzer为test_convert,并在stconvert的基础上指定convert_type为t2s。
DELETE /convert
PUT /convert
{
  "settings": {
    "analysis": {
      "analyzer": {
        "test_convert":{
          "type":"stconvert",
          "convert_type":"t2s"
        }
      }
    }
  }
}
GET /convert/_analyze
{
  "text": ["我愛北京天安門Yeah"]
  ,"analyzer": "test_convert"
}

image.png

相关实践学习
使用阿里云Elasticsearch体验信息检索加速
通过创建登录阿里云Elasticsearch集群,使用DataWorks将MySQL数据同步至Elasticsearch,体验多条件检索效果,简单展示数据同步和信息检索加速的过程和操作。
ElasticSearch 入门精讲
ElasticSearch是一个开源的、基于Lucene的、分布式、高扩展、高实时的搜索与数据分析引擎。根据DB-Engines的排名显示,Elasticsearch是最受欢迎的企业搜索引擎,其次是Apache Solr(也是基于Lucene)。 ElasticSearch的实现原理主要分为以下几个步骤: 用户将数据提交到Elastic Search 数据库中 通过分词控制器去将对应的语句分词,将其权重和分词结果一并存入数据 当用户搜索数据时候,再根据权重将结果排名、打分 将返回结果呈现给用户 Elasticsearch可以用于搜索各种文档。它提供可扩展的搜索,具有接近实时的搜索,并支持多租户。
相关文章
|
26天前
|
存储 运维 监控
金融场景 PB 级大规模日志平台:中信银行信用卡中心从 Elasticsearch 到 Apache Doris 的先进实践
中信银行信用卡中心每日新增日志数据 140 亿条(80TB),全量归档日志量超 40PB,早期基于 Elasticsearch 构建的日志云平台,面临存储成本高、实时写入性能差、文本检索慢以及日志分析能力不足等问题。因此使用 Apache Doris 替换 Elasticsearch,实现资源投入降低 50%、查询速度提升 2~4 倍,同时显著提高了运维效率。
金融场景 PB 级大规模日志平台:中信银行信用卡中心从 Elasticsearch 到 Apache Doris 的先进实践
|
5月前
|
数据可视化 Java Windows
Elasticsearch入门-环境安装ES和Kibana以及ES-Head可视化插件和浏览器插件es-client
本文介绍了如何在Windows环境下安装Elasticsearch(ES)、Elasticsearch Head可视化插件和Kibana,以及如何配置ES的跨域问题,确保Kibana能够连接到ES集群,并提供了安装过程中可能遇到的问题及其解决方案。
Elasticsearch入门-环境安装ES和Kibana以及ES-Head可视化插件和浏览器插件es-client
|
5月前
|
存储 关系型数据库 MySQL
浅谈Elasticsearch的入门与实践
本文主要围绕ES核心特性:分布式存储特性和分析检索能力,介绍了概念、原理与实践案例,希望让读者快速理解ES的核心特性与应用场景。
171 12
|
2月前
|
数据采集 人工智能 运维
从企业级 RAG 到 AI Assistant,阿里云Elasticsearch AI 搜索技术实践
本文介绍了阿里云 Elasticsearch 推出的创新型 AI 搜索方案
205 3
从企业级 RAG 到 AI Assistant,阿里云Elasticsearch AI 搜索技术实践
|
1月前
|
数据采集 人工智能 运维
从企业级 RAG 到 AI Assistant,阿里云Elasticsearch AI 搜索技术实践
本文介绍了阿里云 Elasticsearch 推出的创新型 AI 搜索方案。
209 5
|
3月前
|
存储 安全 数据管理
如何在 Rocky Linux 8 上安装和配置 Elasticsearch
本文详细介绍了在 Rocky Linux 8 上安装和配置 Elasticsearch 的步骤,包括添加仓库、安装 Elasticsearch、配置文件修改、设置内存和文件描述符、启动和验证 Elasticsearch,以及常见问题的解决方法。通过这些步骤,你可以快速搭建起这个强大的分布式搜索和分析引擎。
103 5
|
3月前
|
存储 监控 安全
|
3月前
|
存储 数据采集 监控
开源日志分析Elasticsearch
【10月更文挑战第22天】
68 5
|
4月前
|
存储 JSON Java
elasticsearch学习一:了解 ES,版本之间的对应。安装elasticsearch,kibana,head插件、elasticsearch-ik分词器。
这篇文章是关于Elasticsearch的学习指南,包括了解Elasticsearch、版本对应、安装运行Elasticsearch和Kibana、安装head插件和elasticsearch-ik分词器的步骤。
412 0
elasticsearch学习一:了解 ES,版本之间的对应。安装elasticsearch,kibana,head插件、elasticsearch-ik分词器。
|
6月前
|
人工智能 自然语言处理 搜索推荐
阿里云Elasticsearch AI搜索实践
本文介绍了阿里云 Elasticsearch 在AI 搜索方面的技术实践与探索。
19304 21

热门文章

最新文章

相关产品

  • 检索分析服务 Elasticsearch版