CN113204588A - 一种基于ElasticSearch快速搭建搜索平台的方法 - Google Patents

一种基于ElasticSearch快速搭建搜索平台的方法 Download PDF

Info

Publication number
CN113204588A
CN113204588A CN202110539669.8A CN202110539669A CN113204588A CN 113204588 A CN113204588 A CN 113204588A CN 202110539669 A CN202110539669 A CN 202110539669A CN 113204588 A CN113204588 A CN 113204588A
Authority
CN
China
Prior art keywords
elasticsearch
search
platform
data
sql
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110539669.8A
Other languages
English (en)
Inventor
吴志华
陆昕
鲍碧波
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Green Man Technology Co ltd
Original Assignee
Green Man Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Green Man Technology Co ltd filed Critical Green Man Technology Co ltd
Priority to CN202110539669.8A priority Critical patent/CN113204588A/zh
Publication of CN113204588A publication Critical patent/CN113204588A/zh
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2458Special types of queries, e.g. statistical queries, fuzzy queries or distributed queries
    • G06F16/2471Distributed queries
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/25Integrating or interfacing systems involving database management systems
    • G06F16/252Integrating or interfacing systems involving database management systems between a Database Management System and a front-end application
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • General Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Computational Linguistics (AREA)
  • Mathematical Physics (AREA)
  • Software Systems (AREA)
  • Probability & Statistics with Applications (AREA)
  • Fuzzy Systems (AREA)
  • Computing Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明涉及数据存储搜索技术领域,尤其是一种基于ElasticSearch快速搭建搜索平台的方法,其步骤为:(1)设定平台化搜索架构;(2)基于平台化搜索架构设定关系型数据库和与关系型数据库匹配的数据转换中间件;(3)设定ElasticSearch服务平台,将数据转换中间件与ElasticSearch服务平台数据对接;(4)设定SQL转DSL引擎模块,将SQL转DSL引擎模块与ElasticSearch服务平台数据对接;(5)设定统一API层和业务层,通过统一API层将业务层与SQL转DSL引擎模块之间进行数据对接,本发明实现快速搭建平台化的搜索引擎,支持近实时的查询。

Description

一种基于ElasticSearch快速搭建搜索平台的方法
技术领域
本发明涉及数据存储搜索技术领域,具体领域为一种基于ElasticSearch快速搭建搜索平台的方法。
背景技术
一般企业初期会选择关系型库Mysql做为数据存储。随着业务增长,数据量每日剧增,对于部分场景,关系型库无法满足时。Elasticsearch做为一个分布式、高扩展、高实时的搜索与数据分析引擎,能够很方便的使大量数据具有搜索、分析能力。对于开发中Elasticsearch的引入,相应的要考虑数据同步的实现、Elasticsearch数据搜索业务接口实现。
发明内容
针对现有技术存在的不足,本发明的目的在于提供一种基于ElasticSearch快速搭建搜索平台的方法。
为实现上述目的,本发明提供如下技术方案:一种基于ElasticSearch快速搭建搜索平台的方法,其步骤为:
(1)设定平台化搜索架构;
(2)基于平台化搜索架构设定关系型数据库和与关系型数据库匹配的数据转换中间件;
(3)设定ElasticSearch服务平台,将数据转换中间件与ElasticSearch服务平台数据对接;
(4)设定SQL转DSL引擎模块,将SQL转DSL引擎模块与ElasticSearch服务平台数据对接;
(5)设定统一API层和业务层,通过统一API层将业务层与SQL转DSL引擎模块之间进行数据对接;
所述的平台化搜索架构包括服务器和设置在服务器内的数据转换中间件、ElasticSearch服务平台、SQL转DSL引擎模块、统一API层和业务层,业务层为图形化界面操作模块,统一API层用于设置ElasticSearch服务平台对外暴露的统一接口和分装ElasticSearch服务平台的查询接口,数据转换中间件用于对关系型数据库的异构数据进行处理并同步到ElasticSearch服务平台,SQL转DSL引擎模块用于将外部的SQL查询语言转换为DSL查询语言并输出到ElasticSearch服务平台。
优选的,数据转换中间件的设置为在服务器内配置elasticsearch-jdbc工具,并在elasticsearch-jdbc工具中设置环境变量,然后在服务器中elasticsearch-jdbc工具的根目录下新建odbc_es文件夹,在该文件夹内新建mysql_import_es.sh脚本,然后为该脚本添加可执行权限,通过数据转换中间件完成关系型数据库与ElasticSearch服务平台之间查询数据的同步。
优选的,ElasticSearch服务平台为基于Lucene构建的开源、分布式、Restful搜索引擎,将该引擎嵌入服务器中。
优选的,SQL转DSL引擎模块的设置为构造树形结构的bool query模型,并在bool中嵌套must和should,即boolmust和boolshould,设定查询条件为and时采用boolmust,查询条件为or时采用boolshould,
设定query内部的第一个boolmust作为根节点,内部嵌套的查询条件和第二个boolmust作为第一个boolmust的两个子节点,第二个boolmust作为第三个boolmust的根节点,第二个boolmust内部嵌套的查询条件和第三个boolmust作为第二个boolmust的子节点。
优选的,统一API层的设置为基于 Promise 设计调用fetch api,
fetch api配置为:
fetch(url)
.then(res => res.json())
.then(console.log)
.catch(console.error)。
优选的,业务层包括图形化管理数据和图形化管理Elasticsearch,图形化管理数据用于对关系型数据库的接入配置、以及数据表和Elasticsearch字段数据映射配置,图形化管理Elasticsearch用于对ElasticSearch服务平台中的数据结构进行管理和对集群中的节点进行管理。
优选的,ElasticSearch服务平台的ElasticSearch引擎数量根据实际需求的关系型数据库的容量进行设定。
与现有技术相比,本发明的有益效果是:
1、实现快速搭建平台化的搜索引擎
2、平台搜索支持近实时的查询
3、支持SQL搜索。
附图说明
图1为本发明的原理框图。
具体实施方式
下面将结合本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。
本发明提供一种技术方案:一种基于ElasticSearch快速搭建搜索平台的方法,其步骤为:
(1)设定平台化搜索架构;
(2)基于平台化搜索架构设定关系型数据库和与关系型数据库匹配的数据转换中间件;
(3)设定ElasticSearch服务平台,将数据转换中间件与ElasticSearch服务平台数据对接;
(4)设定SQL转DSL引擎模块,将SQL转DSL引擎模块与ElasticSearch服务平台数据对接;
(5)设定统一API层和业务层,通过统一API层将业务层与SQL转DSL引擎模块之间进行数据对接;
所述的平台化搜索架构包括服务器和设置在服务器内的数据转换中间件、ElasticSearch服务平台、SQL转DSL引擎模块、统一API层和业务层,业务层为图形化界面操作模块,统一API层用于设置ElasticSearch服务平台对外暴露的统一接口和分装ElasticSearch服务平台的查询接口,数据转换中间件用于对关系型数据库的异构数据进行处理并同步到ElasticSearch服务平台,SQL转DSL引擎模块用于将外部的SQL查询语言转换为DSL查询语言并输出到ElasticSearch服务平台。
数据转换中间件的设置为在服务器内配置elasticsearch-jdbc工具,并在elasticsearch-jdbc工具中设置环境变量,
# vi /etc/profile
export JDBC_IMPORTER_HOME=/elasticsearch-jdbc;
使环境变量生效:# source /etc/profile;
然后在服务器中对elasticsearch-jdbc工具进行配置使用,通过在elasticsearch-jdbc工具的根目录下新建文件夹odbc_es:
# ll /odbc_es/
drwxr-xr-x 2 root root 4096 Jun 16 03:11 logs
-rwxrwxrwx 1 root root 542 Jun 16 04:03 mysql_import_es.sh;
然后在该文件夹内新建脚本mysql_import_es.sh:
# cat mysql_import_es.sh
’#!/bin/sh
bin=$JDBC_IMPORTER_HOME/bin
lib=$JDBC_IMPORTER_HOME/lib
echo '{
"type" : "jdbc",
"jdbc": {
"elasticsearch.autodiscover":true,
"elasticsearch.cluster":"my-application",
#簇名,详见:/usr/local/elasticsearch/config/elasticsearch.yml
"url":"jdbc:mysql://10.8.5.101:3306/test", #mysql数据库地址
"user":"root", #mysql用户名
"password":"123456", #mysql密码
"sql":"select * from cc",
"elasticsearch" : {
"host" : "10.8.5.101",
"port" : 9300
},
"index" : "myindex", #新的index
"type" : "mytype" #新的type
}
}'| java \
-cp "${lib}/*" \
-Dlog4j.configurationFile=${bin}/log4j2.xml \
org.xbib.tools.Runner \
org.xbib.tools.JDBCImporter;
然后为该脚本mysql_import_es.sh 添加可执行权限:# chmod a+x mysql_import_es.sh;
执行脚本mysql_import_es.sh:
# ./mysql_import_es.sh;
通过数据转换中间件完成关系型数据库与ElasticSearch服务平台之间查询数据的同步。
上述中间件设置完成后,使用elasticsearch检索查询,测试数据同步是否成功:
# curl -XGET 'http://10.8.5.101:9200/myindex/mytype/_search pretty'
{
"took" : 4,
"timed_out" : false,
"_shards" : {
"total" : 8,
"successful" : 8,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : 1.0,
"hits" : [ {
"_index" : "myindex",
"_type" : "mytype",
"_id" : "AVVXKgeEun6ksbtikOWH",
"_score" : 1.0,
"_source" : {
"id" : 1,
"name" : "laoyang"
}
}, {
"_index" : "myindex",
"_type" : "mytype",
"_id" : "AVVXKgeEun6ksbtikOWI",
"_score" : 1.0,
"_source" : {
"id" : 2,
"name" : "dluzhang"
}
}, {
"_index" : "myindex",
"_type" : "mytype",
"_id" : "AVVXKgeEun6ksbtikOWJ",
"_score" : 1.0,
"_source" : {
"id" : 3,
"name" : "dlulaoyang"
}
} ]
}
};
出现以上包含mysql数据字段的信息则为同步成功。
ElasticSearch服务平台为基于Lucene构建的开源、分布式、Restful搜索引擎,将该引擎嵌入服务器中。
SQL转DSL引擎模块的设置为构造树形结构的bool query模型,并在bool中嵌套must和should,即boolmust和boolshould,设定查询条件为and时采用boolmust,查询条件为or时采用boolshould,
设定query内部的第一个boolmust作为根节点,内部嵌套的查询条件和第二个boolmust作为第一个boolmust的两个子节点,第二个boolmust作为第三个boolmust的根节点,第二个boolmust内部嵌套的查询条件和第三个boolmust作为第二个boolmust的子节点。
sql的select语句在被解析之后生成一个Select的结构体,其where结构可解析为AST抽象语法树,根据查询条件的数量生成相应数量的节点,每个节点为一个ComparisonExpr表达式,这个“比较表达式”即是所有复杂AST的叶子节点。叶子结点在AST遍历的时候一般也就是递归的终点。
当通过SQL转DSL引擎模块进行转换,例如查询条件为a and (b and c)时,query{
boolmust {
a,
boolmust {
b,
c
}
}
};
把query内部的第一个boolmust当作根节点,内部嵌套的a和另一个boolmust当作它的两个子节点,然后b和c又是这个boolmust的子节点。可以看出来,实际上这棵树和AST的节点可以一一对应;
当查询条件为a and (b and (c or d) and e):即,
query {
boolmust {
a,
boolmust {
b,
boolshould {
c,
d
},
e
}
}
};
上述内容与sql的where解析后的AST树进行比较为完全匹配,因此对sql解析生成的AST进行递归,即可得到这棵树。
另外,如果子节点的类型和父节点的类型一致,例如都是and表达式或者都是or表达式,可以在生成dsl的时候将其作为并列的节点进行合并。
统一API层的设置为基于 Promise 设计调用fetch api,
fetch api配置为:
fetch(url)
.then(res => res.json())
.then(console.log)
.catch(console.error)。
async/await
try {
const data = await fetch(url).then(res => res.json())
console.log(data)
} catch (e) {
console.error(e)
};
业务层包括图形化管理数据和图形化管理Elasticsearch,图形化管理数据用于对关系型数据库的接入配置、以及数据表和Elasticsearch字段数据映射配置,图形化管理Elasticsearch用于对ElasticSearch服务平台中的数据结构进行管理和对集群中的节点进行管理。
ElasticSearch服务平台的ElasticSearch引擎数量根据实际需求的关系型数据库的容量进行设定。
尽管已经示出和描述了本发明的实施例,对于本领域的普通技术人员而言,可以理解在不脱离本发明的原理和精神的情况下可以对这些实施例进行多种变化、修改、替换和变型,本发明的范围由所附权利要求及其等同物限定。

Claims (7)

1.一种基于ElasticSearch快速搭建搜索平台的方法,其特征在于:其步骤为:
(1)设定平台化搜索架构;
(2)基于平台化搜索架构设定关系型数据库和与关系型数据库匹配的数据转换中间件;
(3)设定ElasticSearch服务平台,将数据转换中间件与ElasticSearch服务平台数据对接;
(4)设定SQL转DSL引擎模块,将SQL转DSL引擎模块与ElasticSearch服务平台数据对接;
(5)设定统一API层和业务层,通过统一API层将业务层与SQL转DSL引擎模块之间进行数据对接;
所述的平台化搜索架构包括服务器和设置在服务器内的数据转换中间件、ElasticSearch服务平台、SQL转DSL引擎模块、统一API层和业务层,业务层为图形化界面操作模块,统一API层用于设置ElasticSearch服务平台对外暴露的统一接口和分装ElasticSearch服务平台的查询接口,数据转换中间件用于对关系型数据库的异构数据进行处理并同步到ElasticSearch服务平台,SQL转DSL引擎模块用于将外部的SQL查询语言转换为DSL查询语言并输出到ElasticSearch服务平台。
2.根据权利要求1所述的一种基于ElasticSearch快速搭建搜索平台的方法,其特征在于:数据转换中间件的设置为在服务器内配置elasticsearch-jdbc工具,并在elasticsearch-jdbc工具中设置环境变量,然后在服务器中elasticsearch-jdbc工具的根目录下新建odbc_es文件夹,在该文件夹内新建mysql_import_es.sh脚本,然后为该脚本添加可执行权限,通过数据转换中间件完成关系型数据库与ElasticSearch服务平台之间查询数据的同步。
3.根据权利要求1所述的一种基于ElasticSearch快速搭建搜索平台的方法,其特征在于:ElasticSearch服务平台为基于Lucene构建的开源、分布式、Restful搜索引擎,将该引擎嵌入服务器中。
4.根据权利要求1所述的一种基于ElasticSearch快速搭建搜索平台的方法,其特征在于:SQL转DSL引擎模块的设置为构造树形结构的bool query模型,并在bool中嵌套must和should,即boolmust和boolshould,设定查询条件为and时采用boolmust,查询条件为or时采用boolshould,
设定query内部的第一个boolmust作为根节点,内部嵌套的查询条件和第二个boolmust作为第一个boolmust的两个子节点,第二个boolmust作为第三个boolmust的根节点,第二个boolmust内部嵌套的查询条件和第三个boolmust作为第二个boolmust的子节点。
5.根据权利要求1所述的一种基于ElasticSearch快速搭建搜索平台的方法,其特征在于:统一API层的设置为基于 Promise 设计调用fetch api,
fetch api配置为:
fetch(url)
.then(res => res.json())
.then(console.log)
.catch(console.error)。
6.根据权利要求1所述的一种基于ElasticSearch快速搭建搜索平台的方法,其特征在于:业务层包括图形化管理数据和图形化管理Elasticsearch,图形化管理数据用于对关系型数据库的接入配置、以及数据表和Elasticsearch字段数据映射配置,图形化管理Elasticsearch用于对ElasticSearch服务平台中的数据结构进行管理和对集群中的节点进行管理。
7.根据权利要求3所述的一种基于ElasticSearch快速搭建搜索平台的方法,其特征在于:ElasticSearch服务平台的ElasticSearch引擎数量根据实际需求的关系型数据库的容量进行设定。
CN202110539669.8A 2021-05-18 2021-05-18 一种基于ElasticSearch快速搭建搜索平台的方法 Pending CN113204588A (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110539669.8A CN113204588A (zh) 2021-05-18 2021-05-18 一种基于ElasticSearch快速搭建搜索平台的方法

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110539669.8A CN113204588A (zh) 2021-05-18 2021-05-18 一种基于ElasticSearch快速搭建搜索平台的方法

Publications (1)

Publication Number Publication Date
CN113204588A true CN113204588A (zh) 2021-08-03

Family

ID=77031594

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110539669.8A Pending CN113204588A (zh) 2021-05-18 2021-05-18 一种基于ElasticSearch快速搭建搜索平台的方法

Country Status (1)

Country Link
CN (1) CN113204588A (zh)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108491470A (zh) * 2018-03-07 2018-09-04 北京奇安信科技有限公司 针对搜索服务器的管理方法、服务端及管理方法
CN110489445A (zh) * 2019-08-02 2019-11-22 四川宏力信息科技有限责任公司 一种基于多形态复合的海量数据快速查询方法
CN110555152A (zh) * 2018-03-31 2019-12-10 甘肃万维信息技术有限责任公司 基于Elasticsearch框架的分布式搜索系统
CN111506594A (zh) * 2020-04-17 2020-08-07 瑞纳智能设备股份有限公司 一种大数据查询平台及其管理方法和数据查询方法
CN112463886A (zh) * 2020-11-30 2021-03-09 浙江大华技术股份有限公司 一种数据处理方法、装置、电子设备及存储介质

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108491470A (zh) * 2018-03-07 2018-09-04 北京奇安信科技有限公司 针对搜索服务器的管理方法、服务端及管理方法
CN110555152A (zh) * 2018-03-31 2019-12-10 甘肃万维信息技术有限责任公司 基于Elasticsearch框架的分布式搜索系统
CN110489445A (zh) * 2019-08-02 2019-11-22 四川宏力信息科技有限责任公司 一种基于多形态复合的海量数据快速查询方法
CN111506594A (zh) * 2020-04-17 2020-08-07 瑞纳智能设备股份有限公司 一种大数据查询平台及其管理方法和数据查询方法
CN112463886A (zh) * 2020-11-30 2021-03-09 浙江大华技术股份有限公司 一种数据处理方法、装置、电子设备及存储介质

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
XARGIN: "Day4: 《将sql转换为es的DSL》", 《HTTPS://ELASTICSEARCH.CN/ARTICLE/114》 *
佯真愚: "如何构建通用 api 中间层", 《HTTPS://SEGMENTFAULT.COM/A/1190000016966523》 *
铭毅天: "elasticsearch-jdbc实现MySQL同步到ElasticSearch深入详解", 《HTTPS://DEVELOPER.ALIYUN.COM/ARTICLE/708255》 *

Similar Documents

Publication Publication Date Title
US7743066B2 (en) Anonymous types for statically typed queries
Hewitt Cassandra: the definitive guide
Tiwari Professional nosql
US6829606B2 (en) Similarity search engine for use with relational databases
US8417690B2 (en) Automatically avoiding unconstrained cartesian product joins
US20100082646A1 (en) Tracking constraints and dependencies across mapping layers
AU2017269108A1 (en) Optimizing read and write operations in object schema-based application programming interfaces (APIS)
US9251222B2 (en) Abstracted dynamic report definition generation for use within information technology infrastructure
CN102479252A (zh) 查询语句转换装置及查询语句转换方法
US10915535B2 (en) Optimizations for a behavior analysis engine
Biswas et al. Boa meets python: A boa dataset of data science software in python language
Dharmasiri et al. A federated approach on heterogeneous NoSQL data stores
CN117093599A (zh) 面向异构数据源的统一sql查询方法
Nagy et al. Where was this SQL query executed? a static concept location approach
Al Mahruqi et al. A semi-automated framework for migrating web applications from SQL to document oriented NoSQL database.
CN116578585B (zh) 数据查询方法、装置、电子设备及存储介质
CN117421302A (zh) 一种数据处理方法及相关设备
CN113204588A (zh) 一种基于ElasticSearch快速搭建搜索平台的方法
US11188228B1 (en) Graphing transaction operations for transaction compliance analysis
CN114490724B (zh) 处理数据库查询语句的方法和装置
CN115114325B (zh) 数据查询方法、装置、电子设备以及存储介质
CN110472127A (zh) 一种数据查询方法及系统
CN114547083A (zh) 数据处理方法、装置及电子设备
Marchioni MongoDB for Java developers
Janiszewski et al. VARIoT-Vulnerability and Attack Repository for the Internet of Things

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20210803