Skip to content

Elastic

操作ElasticSearch数据库,目前支持的操作类型有getsearchindexupdatedelete

业务属性

属性含义说明输入限定示例值
enable是否启用该控件,未启用时不编译是否编译选择值启用
name控件返回值命名控件输出值变量名常量Elastic
text与控件关联的文本设计页控件显示常量Elastic
elastic检索数据库elastic数据库,需预先在资源配置中配置选择值myElastic
method执行方法get:获取存储在Elasticsearch中的单个文档
search:在Elasticsearch索引中搜索匹配查询条件的文档
index:在Elasticsearch索引中存储或更新文档。文档不存在时创建新文档;文档已存在则更新
update:更新Elasticsearch索引中现有文档的部分字段
delete:从Elasticsearch索引中删除文档
选择值get
index索引常量/流程变量index1
doc_id文档IDmethodget|index|update|delete时可设置常量/流程变量#{docId}
query查询条件methodsearch时可设置常量,Json数据节点可用流程变量/流程变量#{query}
document文档methodindex|update时可设置常量,Json数据节点可用流程变量/流程变量{"a":"#{a}"}
throwable发生异常时中断请求启用:控件执行异常时立即中断请求,并返回错误
禁用:控件执行异常时将被忽略,并继续执行其后的流程
选择值启用

输出值

控件返回以属性name为名称的实体,该实体包含属性resultresult表示操作的Json结果反序列化的实体对象。

使用示例

假设已创建Elastic资源,资源名称为:myElasticElastic中已创建Index,名称为myIndex

示例一:index

当操作的文档已经存在(doc_id相同)时,会被更新

  • Elastic控件设置

添加Elastic控件并命名为elasticIndex,属性设置为:

elasticmyElasticmethodindex

indexmyIndexdoc_idorapisElasticDocId1

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"
}
img_elastic_1.png
  • 输出操作结果

添加输出控件Returndata设置为:

json
{
  "elasticIndex": "#{elasticIndex}"
}
{
  "elasticIndex": "#{elasticIndex}"
}
img_elastic_2.png
  • 接口调用

使用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,属性设置为:

elasticmyElasticmethodget

indexmyIndexdoc_id(示例一中已创建的文档)orapisElasticDocId1

img_elastic_3.png
  • 输出操作结果

添加输出控件Returndata设置为:

json
{
  "elasticGet": "#{elasticGet}"
}
{
  "elasticGet": "#{elasticGet}"
}
img_elastic_4.png
  • 接口调用

使用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,属性设置为:

elasticmyElasticmethodupdate

indexmyIndexdoc_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代表更新文档的节点,当不存在该节点时会新增,否则会被更新

img_elastic_5.png
  • 输出操作结果

添加输出控件Returndata设置为:

json
{
  "elasticUpdate": "#{elasticUpdate}"
}
{
  "elasticUpdate": "#{elasticUpdate}"
}
img_elastic_6.png
  • 接口调用

使用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"
        }
    }
}

按示例一的方法向myIndex中新增文档 orapisElasticDocId2orapisElasticDocId3

  • Elastic控件设置

添加Elastic控件并命名为elasticSearch,属性设置为:

elasticmyElasticmethodsearchindexmyIndex

query为:

json
{
  "query": {
    "match": {
      "content": "orapis"
    }
  }
}
{
  "query": {
    "match": {
      "content": "orapis"
    }
  }
}

查询myIndex所有文档中的content节点包含"orapis"的文档

img_elastic_7.png
  • 输出操作结果

添加输出控件Returndata设置为:

json
{
  "elasticSearch": "#{elasticSearch}"
}
{
  "elasticSearch": "#{elasticSearch}"
}
img_elastic_8.png
  • 接口调用

使用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,属性设置为:

elasticmyElasticmethoddelete

indexmyIndexdoc_id(示例一中已创建的文档)orapisElasticDocId1

img_elastic_9.png
  • 输出操作结果

添加输出控件Returndata设置为:

json
{
  "elasticDelete": "#{elasticDelete}"
}
{
  "elasticDelete": "#{elasticDelete}"
}
img_elastic_10.png
  • 接口调用

使用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"
        }
    }
}