Elasticsearch

对连接器中Elasticsearch(连接Elasticsearch)进行数据转换处理。

接口要求

  1. ES DS支持Elasticsearch的各种查询语法,如term、must、range、sort 等等
  2. 不支持bulk语法

快速上手

本例假设企业的理财产品信息如下,以【搜索产品信息】为例。

//假设某企业品信息如下
{
  "products":[
    {"productName":"理财产品A","annual_rate":"3.2200%","describe":"180天定期理财,最低20000起投,收益稳定,可以自助选择消息推送"}
    {"productName":"理财产品B","annual_rate":"3.1100%","describe":"90天定投产品,最低10000起投,每天收益到账消息推送"}
    {"productName":"理财产品C","annual_rate":"3.3500%","describe":"270天定投产品,最低40000起投,每天收益立即到账消息推送"}
    {"productName":"理财产品D","annual_rate":"3.1200%","describe":"90天定投产品,最低12000起投,每天收益到账消息推送"}
    {"productName":"理财产品E","annual_rate":"3.0100%","describe":"30天定投产品推荐,最低8000起投,每天收益会消息推送"}
    {"productName":"理财产品F","annual_rate":"2.7500%","describe":"热门短期产品,3天短期,无须任何手续费用,最低500起投,通过短信提示获取收益消息"}
  ]
}
  1. 搭建ES服务,维护理财产品信息
  2. 创建ES连接器
  3. 创建ES数据
  4. 配置输入、输出信息
  5. 测试

1.搭建ES服务,维护理财产品信息

有关ES服务的搭建,请自主参阅ES官方网站。此步骤所有准备工作请使用ES客户端工具线下执行完成。不支持在ES DS中完成。

(1).创建一个名称为productfo的索引:

# 适用7.0及以上版本。创建了一个名称为product_info的索引。索引的类型为_doc,并包含了productName、annual_rate和describe字段。

PUT /product_info
{
  "settings": {
    "number_of_shards": 5,
    "number_of_replicas": 1
  },
  "mappings": {
      "properties": {
        "productName": {
          "type": "text",
          "analyzer": "ik_smart"
        },
        "annual_rate":{
          "type":"keyword"
        },
        "describe": {
          "type": "text",
          "analyzer": "ik_smart"
        }
    }
  }
}

# 创建成功后,返回结果如下
{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "index" : "product_info"
}

(2).创建文档并插入数据

# 创建文档并插入数据
POST /product_info/_doc/_bulk
{"index":{}}
{"productName":"理财产品A","annual_rate":"3.2200%","describe":"180天定期理财,最低20000起投,收益稳定,可以自助选择消息推送"}
{"index":{}}
{"productName":"理财产品B","annual_rate":"3.1100%","describe":"90天定投产品,最低10000起投,每天收益到账消息推送"}
{"index":{}}
{"productName":"理财产品C","annual_rate":"3.3500%","describe":"270天定投产品,最低40000起投,每天收益立即到账消息推送"}
{"index":{}}
{"productName":"理财产品D","annual_rate":"3.1200%","describe":"90天定投产品,最低12000起投,每天收益到账消息推送"}
{"index":{}}
{"productName":"理财产品E","annual_rate":"3.0100%","describe":"30天定投产品推荐,最低8000起投,每天收益会消息推送"}
{"index":{}}
{"productName":"理财产品F","annual_rate":"2.7500%","describe":"热门短期产品,3天短期,无须任何手续费用,最低500起投,通过短信提示获取收益消息"}

# 如果返回显示 "errors" : false ,说明数据插入成功。

2.创建ES连接器

在连接服务>连接页面,创建Elasticsearch连接器。

3. 创建ES数据

  • 连接器为上步中创建的连接器,请求方法为GET,API路径为/product_info/_doc/_search

4. 配置输入、输出信息

  • 输入信息可导入生成,导入信息如下:
    {
    "query": {
      "match": {
        "describe": "每天收益到账消息推送"
      }
    }
    }
    
  • 输出信息可直接连线result根节点,或通过导入如下信息自动生成:
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 30,
      "relation" : "eq"
    },
    "max_score" : 3.5053923,
    "hits" : [
      {
        "_index" : "product_info",
        "_type" : "_doc",
        "_id" : "bGaKs4EB1serIi0iKgPK",
        "_score" : 3.5053923,
        "_source" : {
          "productName" : "理财产品D",
          "annual_rate" : "3.1200%",
          "describe" : "90天定投产品,最低12000起投,每天收益到账消息推送"
        }
      },
      {
        "_index" : "product_info",
        "_type" : "_doc",
        "_id" : "xWbEt4EB1serIi0ixmkP",
        "_score" : 3.5053923,
        "_source" : {
          "productName" : "理财产品B",
          "annual_rate" : "3.1100%",
          "describe" : "90天定投产品,最低10000起投,每天收益到账消息推送"
        }
      },
      {
        "_index" : "product_info",
        "_type" : "_doc",
        "_id" : "x2bEt4EB1serIi0ixmkP",
        "_score" : 2.832256,
        "_source" : {
          "productName" : "理财产品D",
          "annual_rate" : "3.1200%",
          "describe" : "90天定投产品,最低12000起投,每天收益到账消息推送"
        }
      },
      {
        "_index" : "product_info",
        "_type" : "_doc",
        "_id" : "amaKs4EB1serIi0iKgPK",
        "_score" : 2.2842526,
        "_source" : {
          "productName" : "理财产品B",
          "annual_rate" : "3.1100%",
          "describe" : "90天定投产品,最低10000起投,每天收益到账消息推送"
        }
      },
      {
        "_index" : "product_info",
        "_type" : "_doc",
        "_id" : "02bEt4EB1serIi0izGkH",
        "_score" : 2.2842526,
        "_source" : {
          "productName" : "理财产品B",
          "annual_rate" : "3.1100%",
          "describe" : "90天定投产品,最低10000起投,每天收益到账消息推送"
        }
      },
      {
        "_index" : "product_info",
        "_type" : "_doc",
        "_id" : "v2bEt4EB1serIi0ivWmH",
        "_score" : 2.217505,
        "_source" : {
          "productName" : "理财产品C",
          "annual_rate" : "3.3500%",
          "describe" : "270天定投产品,最低40000起投,每天收益立即到账消息推送"
        }
      },
      {
        "_index" : "product_info",
        "_type" : "_doc",
        "_id" : "wGbEt4EB1serIi0ivWmH",
        "_score" : 1.918189,
        "_source" : {
          "productName" : "理财产品D",
          "annual_rate" : "3.1200%",
          "describe" : "90天定投产品,最低12000起投,每天收益到账消息推送"
        }
      },
      {
        "_index" : "product_info",
        "_type" : "_doc",
        "_id" : "1WbEt4EB1serIi0izGkH",
        "_score" : 1.918189,
        "_source" : {
          "productName" : "理财产品D",
          "annual_rate" : "3.1200%",
          "describe" : "90天定投产品,最低12000起投,每天收益到账消息推送"
        }
      },
      {
        "_index" : "product_info",
        "_type" : "_doc",
        "_id" : "zWbEt4EB1serIi0iyGm0",
        "_score" : 1.8621383,
        "_source" : {
          "productName" : "理财产品C",
          "annual_rate" : "3.3500%",
          "describe" : "270天定投产品,最低40000起投,每天收益立即到账消息推送"
        }
      },
      {
        "_index" : "product_info",
        "_type" : "_doc",
        "_id" : "1GbEt4EB1serIi0izGkH",
        "_score" : 1.8621383,
        "_source" : {
          "productName" : "理财产品C",
          "annual_rate" : "3.3500%",
          "describe" : "270天定投产品,最低40000起投,每天收益立即到账消息推送"
        }
      }
    ]
  }
}

5. 保存测试

配置完成后点击保存,然后点击测试一下按钮,打开侧边栏describe 参数值输入 【每天收益到账消息推送】,点击执行按钮,查看测试结果。



Seven
 010-62962343-690
 liujx@actionsoft.com.cn
感谢您对该文档的关注!如果您对当前页面内容有疑问或好的建议,请与我联系。如果您需要解答相关技术问题请登录AWS客户成功社区