阿里云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实现地理位置查询
本实验将分别介绍如何使用Elasticsearch7.10版本进行全文检索、多语言检索和地理位置查询三个Elasticsearch基础检索子场景的实现。
ElasticSearch 入门精讲
ElasticSearch是一个开源的、基于Lucene的、分布式、高扩展、高实时的搜索与数据分析引擎。根据DB-Engines的排名显示,Elasticsearch是最受欢迎的企业搜索引擎,其次是Apache Solr(也是基于Lucene)。 ElasticSearch的实现原理主要分为以下几个步骤: 用户将数据提交到Elastic Search 数据库中 通过分词控制器去将对应的语句分词,将其权重和分词结果一并存入数据 当用户搜索数据时候,再根据权重将结果排名、打分 将返回结果呈现给用户 Elasticsearch可以用于搜索各种文档。它提供可扩展的搜索,具有接近实时的搜索,并支持多租户。
相关文章
|
15天前
|
运维 监控 Java
探索Elasticsearch在Java环境下的全文检索应用实践
【6月更文挑战第30天】在大数据背景下,Elasticsearch作为分布式搜索分析引擎,因其扩展性和易用性备受青睐。本文指导在Java环境中集成Elasticsearch,涉及安装配置、使用RestHighLevelClient连接、索引与文档操作,如创建索引、插入文档及全文检索查询。此外,还讨论了高级查询、性能优化和故障排查,帮助开发者高效处理非结构化数据全文检索。
31 0
|
6天前
|
机器人 API 开发工具
阿里云百炼应用实践系列-基于LlamaIndex的文档问答助手
本文以百炼官方文档问答助手为例,介绍如何基于百炼平台打造基于LlamaIndex的RAG文档问答产品。我们基于百炼平台的底座能力,以官方帮助文档为指定知识库,搭建了问答服务,支持钉钉、Web访问。介绍了相关技术方案和主要代码,供开发者参考。
|
1天前
|
Docker 容器
docker desktop安装es并连接elasticsearch-head:5
以上就是在Docker Desktop上安装Elasticsearch并连接Elasticsearch-head:5的步骤。
11 2
|
6天前
|
数据采集 运维 Cloud Native
Flink+Paimon在阿里云大数据云原生运维数仓的实践
构建实时云原生运维数仓以提升大数据集群的运维能力,采用 Flink+Paimon 方案,解决资源审计、拓扑及趋势分析需求。
356 0
Flink+Paimon在阿里云大数据云原生运维数仓的实践
|
10天前
|
弹性计算
软件开发常见流程之阿里云如何安装宝塔,配置安全组
软件开发常见流程之阿里云如何安装宝塔,配置安全组
|
12天前
|
关系型数据库 分布式数据库 数据库
PolarDB,阿里云的开源分布式数据库,与微服务相结合,提供灵活扩展和高效管理解决方案。
【7月更文挑战第3天】PolarDB,阿里云的开源分布式数据库,与微服务相结合,提供灵活扩展和高效管理解决方案。通过数据分片和水平扩展支持微服务弹性,保证高可用性,且兼容MySQL协议,简化集成。示例展示了如何使用Spring Boot配置PolarDB,实现服务动态扩展。PolarDB缓解了微服务数据库挑战,加速了开发部署,为云原生应用奠定基础。
153 3
|
13天前
|
Linux Python
【Elasticsearch】linux使用supervisor常驻Elasticsearch,centos6.10安装 supervisor
【Elasticsearch】linux使用supervisor常驻Elasticsearch,centos6.10安装 supervisor
14 3
|
17天前
|
持续交付 开发工具 git
阿里云云效产品使用问题之在云效代码域中gitlab使用docker安装的,迁移时遇到“获取企业信息失败”,是什么原因
云效作为一款全面覆盖研发全生命周期管理的云端效能平台,致力于帮助企业实现高效协同、敏捷研发和持续交付。本合集收集整理了用户在使用云效过程中遇到的常见问题,问题涉及项目创建与管理、需求规划与迭代、代码托管与版本控制、自动化测试、持续集成与发布等方面。
|
16天前
|
运维 Kubernetes 安全
《阿里云产品四月刊》—享道出行:容器弹性技术驱动下的智慧出行稳定性实践(1)
阿里云瑶池数据库云原生化和一体化产品能力升级,多款产品更新迭代
|
16天前
|
弹性计算 Cloud Native 数据库
《阿里云产品四月刊》—享道出行:容器弹性技术驱动下的智慧出行稳定性实践(2)
阿里云瑶池数据库云原生化和一体化产品能力升级,多款产品更新迭代

热门文章

最新文章

相关产品

  • 检索分析服务 Elasticsearch版