Elasticsearch下应用Siren Federate插件
插件下载
https://siren.io/downloads/?product=siren-federate
下载到的文件名是:siren-federate-6.8.2-10.3.1.zip,(版本差异可能文件名不同)。
解压缩
下载zip文件后,解压缩到某个文件夹,比如我这里就解压缩到了:
D:\software\ELK-v6.8.2\siren-federate-6.8.2-10.3.1
安装
在Windows命令提示符下面,进入Elasticsearch所在的目录:
C:\ELK\elasticsearch-6.8.2\bin>elasticsearch-plugin install file:///D:/software/ELK-v6.8.2/siren-federate-6.8.2-10.3.1/siren-federate-6.8.2-10.3.1-proguard-plugin.zip
创建并上传两个indices
首先要安装一个Cygwin客户端,在Cygwin的控制台里面以此执行下面5条命令:
$ curl -H 'Content-Type: application/json' -XPUT 'http://localhost:9200/articles'
$ curl -H 'Content-Type: application/json' -XPUT 'http://localhost:9200/articles/_mapping/article' -d '
{
"properties": {
"mentions": {
"type": "keyword"
}
}
}
'
$ curl -H 'Content-Type: application/json' -XPUT 'http://localhost:9200/companies'
$ curl -H 'Content-Type: application/json' -XPUT 'http://localhost:9200/companies/_mapping/company' -d '
{
"properties": {
"id": {
"type": "keyword"
}
}
}
'
$ curl -H 'Content-Type: application/json' -XPUT 'http://localhost:9200/_bulk?pretty' -d '
{ "index" : { "_index" : "articles", "_type" : "article", "_id" : "1" } }
{ "title" : "The NoSQL database glut", "mentions" : ["1", "2"] }
{ "index" : { "_index" : "articles", "_type" : "article", "_id" : "2" } }
{ "title" : "Graph Databases Seen Connecting the Dots", "mentions" : [] }
{ "index" : { "_index" : "articles", "_type" : "article", "_id" : "3" } }
{ "title" : "How to determine which NoSQL DBMS best fits your needs", "mentions" : ["2", "4"] }
{ "index" : { "_index" : "articles", "_type" : "article", "_id" : "4" } }
{ "title" : "MapR ships Apache Drill", "mentions" : ["4"] }
{ "index" : { "_index" : "companies", "_type" : "company", "_id" : "1" } }
{ "id": "1", "name" : "Elastic" }
{ "index" : { "_index" : "companies", "_type" : "company", "_id" : "2" } }
{ "id": "2", "name" : "Orient Technologies" }
{ "index" : { "_index" : "companies", "_type" : "company", "_id" : "3" } }
{ "id": "3", "name" : "Cloudera" }
{ "index" : { "_index" : "companies", "_type" : "company", "_id" : "4" } }
{ "id": "4", "name" : "MapR" }
'
这样就生成了两个indice,如果以表格的形式展示,就是这样的:
Companies
id | name |
---|---|
1 | Elastic |
2 | Orient Technologies |
3 | Cloudera |
4 | MapR |
articles
mentions | title |
---|---|
Graph Databases Seen Connecting the Dots | |
4 | MapR ships Apache Drill |
1, 2 | The NoSQL database glut |
2, 4 | How to determine which NoSQL DBMS best fits your needs |
Join查询
$ curl -H 'Content-Type: application/json' 'http://localhost:9200/siren/articles/_search?pretty' -d '{
"query" : {
"join" : {
"indices" : ["companies"],
"on" : ["mentions", "id"],
"request" : {
"query" : {
"term" : {
"name" : "orient"
}
}
}
}
}
}'
Join在DevTools中查询
GET /siren/companies/_search
{
"query" : {
"join" : {
"indices" : ["companies"],
"on" : ["mentions", "id"],
"request" : {
"query" : {
"term" : {
"name" : "orient"
}
}
}
}
}
}
得到的结果:
{
"took" : 198,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 0.0,
"hits" : [
{
"_index" : "articles",
"_type" : "article",
"_id" : "1",
"_score" : 0.0,
"_source" : {
"title" : "The NoSQL database glut",
"mentions" : [
"1",
"2"
]
}
},
{
"_index" : "articles",
"_type" : "article",
"_id" : "3",
"_score" : 0.0,
"_source" : {
"title" : "How to determine which NoSQL DBMS best fits your needs",
"mentions" : [
"2",
"4"
]
}
}
]
},
"planner" : {
"node" : "OWQQ6GlWTU-4zKyp_pCPaQ",
"took_in_millis" : 2214,
"timestamp" : {
"start_in_millis" : 1569742126495,
"stop_in_millis" : 1569742128709,
"took_in_millis" : 2214
},
"is_pruned" : false
}
}
生成安全码:
D:\DSUsers\uidt8491\ELK\elasticsearch-6.8.2\plugins\siren-federate\tools>java -cp ..\* io.siren.federate.tools.KeyGen -s 128