Appearance
Elastic
操作ElasticSearch数据库,目前支持的操作类型有get
、search
、index
、update
、delete
业务属性
属性 | 含义 | 说明 | 输入限定 | 示例值 |
---|---|---|---|---|
enable | 是否启用该控件,未启用时不编译 | 是否编译 | 选择值 | 启用 |
name | 控件返回值命名 | 控件输出值变量名 | 常量 | Elastic |
text | 与控件关联的文本 | 设计页控件显示 | 常量 | Elastic |
elastic | 检索数据库 | elastic数据库,需预先在资源配置中配置 | 选择值 | myElastic |
method | 执行方法 | get:获取存储在Elasticsearch中的单个文档 search:在Elasticsearch索引中搜索匹配查询条件的文档 index:在Elasticsearch索引中存储或更新文档。文档不存在时创建新文档;文档已存在则更新 update:更新Elasticsearch索引中现有文档的部分字段 delete:从Elasticsearch索引中删除文档 | 选择值 | get |
index | 索引 | 常量 /流程变量 | index1 | |
doc_id | 文档ID | method为get|index|update|delete时可设置 | 常量 /流程变量 | #{docId} |
query | 查询条件 | method为search时可设置 | 常量,Json数据节点可用流程变量 /流程变量 | #{query} |
document | 文档 | method为index|update时可设置 | 常量,Json数据节点可用流程变量 /流程变量 | {"a":"#{a}"} |
throwable | 发生异常时中断请求 | 启用:控件执行异常时立即中断请求,并返回错误 禁用:控件执行异常时将被忽略,并继续执行其后的流程 | 选择值 | 启用 |
输出值
控件返回以属性name为名称的实体,该实体包含属性result,result表示操作的Json结果反序列化的实体对象。
使用示例
假设已创建Elastic资源,资源名称为:myElastic
;Elastic中已创建Index,名称为myIndex
。
示例一:index
当操作的文档已经存在(doc_id相同)时,会被更新
- Elastic控件设置
添加Elastic控件并命名为elasticIndex
,属性设置为:
elastic:myElastic
; method:index
index:myIndex
; doc_id:orapisElasticDocId1
document为:
json
{
"title": "ElasticDoc1",
"content": "This is document 1 for testing elastic controls for orapis"
}
{
"title": "ElasticDoc1",
"content": "This is document 1 for testing elastic controls for orapis"
}

- 输出操作结果
添加输出控件Return,data设置为:
json
{
"elasticIndex": "#{elasticIndex}"
}
{
"elasticIndex": "#{elasticIndex}"
}

- 接口调用
使用curl请求接口:
$ curl http://localhost:6636/api/elasticIndex
$ curl http://localhost:6636/api/elasticIndex
接口返回:
json
{
"elasticIndex": {
"result": {
"_type": "_doc",
"_index": "myIndex",
"_id": "orapisElasticDocId1",
"_primary_term": 1,
"_shards": {
"failed": 0,
"total": 1,
"successful": 1
},
"result": "created",
"_version": 1,
"_seq_no": 8
}
}
}
{
"elasticIndex": {
"result": {
"_type": "_doc",
"_index": "myIndex",
"_id": "orapisElasticDocId1",
"_primary_term": 1,
"_shards": {
"failed": 0,
"total": 1,
"successful": 1
},
"result": "created",
"_version": 1,
"_seq_no": 8
}
}
}
示例二:get
- Elastic控件设置
添加Elastic控件并命名为elasticGet
,属性设置为:
index:myIndex
; doc_id:(示例一中已创建的文档)orapisElasticDocId1

- 输出操作结果
添加输出控件Return,data设置为:
json
{
"elasticGet": "#{elasticGet}"
}
{
"elasticGet": "#{elasticGet}"
}

- 接口调用
使用curl请求接口:
$ curl http://localhost:6636/api/elasticGet
$ curl http://localhost:6636/api/elasticGet
接口返回:
json
{
"elasticGet": {
"result": {
"_type": "_doc",
"_primary_term": 1,
"found": true,
"_index": "myIndex",
"_id": "orapisElasticDocId1",
"_source": {
"content": "This is document 1 for testing elastic controls for orapis",
"title": "ElasticDoc1"
},
"_seq_no": 8,
"_version": 1
}
}
}
{
"elasticGet": {
"result": {
"_type": "_doc",
"_primary_term": 1,
"found": true,
"_index": "myIndex",
"_id": "orapisElasticDocId1",
"_source": {
"content": "This is document 1 for testing elastic controls for orapis",
"title": "ElasticDoc1"
},
"_seq_no": 8,
"_version": 1
}
}
}
示例三:update
- Elastic控件设置
添加Elastic控件并命名为elasticUpdate
,属性设置为:
elastic:myElastic
; method:update
index:myIndex
; doc_id:(示例一中已创建的文档)orapisElasticDocId1
document为:
json
{
"doc": {
"content": "This is the updated content of document 1 for testing elastic controls for orapis"
}
}
{
"doc": {
"content": "This is the updated content of document 1 for testing elastic controls for orapis"
}
}
document代表更新文档的节点,当不存在该节点时会新增,否则会被更新

- 输出操作结果
添加输出控件Return,data设置为:
json
{
"elasticUpdate": "#{elasticUpdate}"
}
{
"elasticUpdate": "#{elasticUpdate}"
}

- 接口调用
使用curl请求接口:
$ curl http://localhost:6636/api/elasticUpdate
$ curl http://localhost:6636/api/elasticUpdate
接口返回:
json
{
"elasticUpdate": {
"result": {
"_version": 2,
"_type": "_doc",
"_index": "myIndex",
"_id": "orapisElasticDocId1",
"_shards": {
"successful": 1,
"failed": 0,
"total": 1
},
"_seq_no": 9,
"_primary_term": 1,
"result": "updated"
}
}
}
{
"elasticUpdate": {
"result": {
"_version": 2,
"_type": "_doc",
"_index": "myIndex",
"_id": "orapisElasticDocId1",
"_shards": {
"successful": 1,
"failed": 0,
"total": 1
},
"_seq_no": 9,
"_primary_term": 1,
"result": "updated"
}
}
}
示例四:search
按示例一的方法向myIndex中新增文档 orapisElasticDocId2
和orapisElasticDocId3
- Elastic控件设置
添加Elastic控件并命名为elasticSearch
,属性设置为:
elastic:myElastic
; method:search
; index:myIndex
;
query为:
json
{
"query": {
"match": {
"content": "orapis"
}
}
}
{
"query": {
"match": {
"content": "orapis"
}
}
}
查询myIndex所有文档中的content节点包含"orapis"的文档

- 输出操作结果
添加输出控件Return,data设置为:
json
{
"elasticSearch": "#{elasticSearch}"
}
{
"elasticSearch": "#{elasticSearch}"
}

- 接口调用
使用curl请求接口:
$ curl http://localhost:6636/api/elasticSearch
$ curl http://localhost:6636/api/elasticSearch
接口返回:
json
{
"elasticSearch": {
"result": {
"took": 553,
"timed_out": false,
"_shards": {
"successful": 1,
"skipped": 0,
"failed": 0,
"total": 1
},
"hits": {
"max_score": 0.08701137,
"hits": [
{
"_type": "_doc",
"_source": {
"title": "ElasticDoc1",
"content": "This is document 1 for testing elastic controls for orapis",
"doc": {
"content": "This is the updated content of document 1 for testing elastic controls for orapis"
}
},
"_index": "myIndex",
"_id": "orapisElasticDocId1",
"_score": 0.08701137
},
{
"_type": "_doc",
"_source": {
"content": "This is document 3 for testing elastic controls for orapis",
"title": "ElasticDoc3"
},
"_index": "myIndex",
"_id": "orapisElasticDocId3",
"_score": 0.08701137
},
{
"_type": "_doc",
"_source": {
"content": "This is document 2 for testing elastic controls for orapis",
"title": "ElasticDoc2"
},
"_index": "myIndex",
"_id": "orapisElasticDocId2",
"_score": 0.08701137
}
],
"total": {
"value": 3,
"relation": "eq"
}
}
}
}
}
{
"elasticSearch": {
"result": {
"took": 553,
"timed_out": false,
"_shards": {
"successful": 1,
"skipped": 0,
"failed": 0,
"total": 1
},
"hits": {
"max_score": 0.08701137,
"hits": [
{
"_type": "_doc",
"_source": {
"title": "ElasticDoc1",
"content": "This is document 1 for testing elastic controls for orapis",
"doc": {
"content": "This is the updated content of document 1 for testing elastic controls for orapis"
}
},
"_index": "myIndex",
"_id": "orapisElasticDocId1",
"_score": 0.08701137
},
{
"_type": "_doc",
"_source": {
"content": "This is document 3 for testing elastic controls for orapis",
"title": "ElasticDoc3"
},
"_index": "myIndex",
"_id": "orapisElasticDocId3",
"_score": 0.08701137
},
{
"_type": "_doc",
"_source": {
"content": "This is document 2 for testing elastic controls for orapis",
"title": "ElasticDoc2"
},
"_index": "myIndex",
"_id": "orapisElasticDocId2",
"_score": 0.08701137
}
],
"total": {
"value": 3,
"relation": "eq"
}
}
}
}
}
示例五:delete
- Elastic控件设置
添加Elastic控件并命名为elasticDelete
,属性设置为:
elastic:myElastic
; method:delete
index:myIndex
; doc_id:(示例一中已创建的文档)orapisElasticDocId1

- 输出操作结果
添加输出控件Return,data设置为:
json
{
"elasticDelete": "#{elasticDelete}"
}
{
"elasticDelete": "#{elasticDelete}"
}

- 接口调用
使用curl请求接口:
$ curl http://localhost:6636/api/elasticDelete
$ curl http://localhost:6636/api/elasticDelete
接口返回:
json
{
"elasticDelete": {
"result": {
"_index": "myIndex",
"_id": "orapisElasticDocId1",
"_primary_term": 1,
"_seq_no": 14,
"_version": 3,
"result": "deleted",
"_shards": {
"successful": 1,
"failed": 0,
"total": 1
},
"_type": "_doc"
}
}
}
{
"elasticDelete": {
"result": {
"_index": "myIndex",
"_id": "orapisElasticDocId1",
"_primary_term": 1,
"_seq_no": 14,
"_version": 3,
"result": "deleted",
"_shards": {
"successful": 1,
"failed": 0,
"total": 1
},
"_type": "_doc"
}
}
}