Logstash jdbc输入插件给出了日期映射错误,同时将数据索引到postgres的弹性搜索中

时间:2016-03-03 20:44:00

标签: elasticsearch logstash logstash-jdbc

背景 我试图将Postgres的数据索引到弹性搜索中,并遵循以下步骤:

第1步: - 使用logstash jdbc-input插件从Postgres批量导入数据。 步骤2: - 使用弹性搜索REST Apis(用于CRUD)从应用程序同步进一步的元数据更改。

一开始,我在弹性搜索中创建了文档映射,如下所示: -

   {"metatestsample": {
        "properties": {
           "business_number": {
              "type": "long"
           },
           "business_number_type": {
              "type": "string",
              "index":"not_analyzed"
           },
           "document_id": {
              "type": "long"
           },
           "document_location": {
              "type": "string",
              "index":"not_analyzed"
           },
           "document_number": {
              "type": "string",
              "index":"not_analyzed"
           },
           "document_status": {
              "type": "string",
              "index":  "not_analyzed"
           },
           "country": {
              "type": "string",
              "index":  "not_analyzed"
           },
           "document_created": {
              "type": "date",
              "format": "yyyy-MM-dd'T'HH:mm:ss"
           },
           "customer": {
              "properties": {
                 "customer_id": {
                    "type": "long"
                 },
                 "customer_number": {
                    "type": "string",
                    "index":  "not_analyzed"
                 },
                 "customer_name": {
                    "type": "string",
                    "index":  "not_analyzed"
                 },
                 "address1":{
                    "type": "string",
                    "index":  "not_analyzed"
                 },
                 "address2":{
                    "type": "string",
                    "index":  "not_analyzed"
                 },
                 "city":{
                    "type": "string",
                    "index":  "not_analyzed"
                 },
                 "state":{
                    "type": "string",
                    "index":  "not_analyzed"
                 },
                 "zip":{
                    "type": "string",
                    "index":  "not_analyzed"
                 },
                 "country":{
                    "type": "string",
                    "index":  "not_analyzed"
                 },
                 "phone":{
                    "type": "string",
                    "index":  "not_analyzed"
                 },
                 "fax":{
                    "type": "string",
                    "index":  "not_analyzed"
                 },
                 "email":{
                    "type": "string",
                    "index":  "not_analyzed"
                 },
                 "contact_name":{
                    "type": "string",
                    "index":  "not_analyzed"
                 },
                 "customer_created":{
                    "type": "date",
                    "format": "yyyy-MM-dd'T'HH:mm:ss"
                 },
                 "customer_modified":{
                    "type": "date",
                    "format": "yyyy-MM-dd'T'HH:mm:ss"
                 },
                 "type":{
                    "type": "string",
                    "index":  "not_analyzed"
                 }
              }
           },

           "expiration_date": {
              "type": "date",
              "format": "YYYY-MM-DD"
           },
           "legacy_document_id": {
              "type": "string"
           },
           "document_modified": {
              "type": "date",
              "format": "yyyy-MM-dd'T'HH:mm:ss"
           },
           "review_date": {
              "type": "date",
              "format": "YYYY-MM-DD"
           },
           "valid": {
              "type": "boolean"
           },
           "invalid_reason": {
              "type": "string",
              "index":  "not_analyzed"
           }
        }
     } }

并为jdbc输入插件添加了logstash配置: -

  input{
    jdbc {
         # Postgres jdbc connection string to our database, mydb
         jdbc_connection_string => "jdbc:postgresql://localhost:5432/mydb"
         # The user we wish to execute our statement as
         jdbc_user => "user"
         jdbc_password => "password"
         # The path to our downloaded jdbc driver
         jdbc_driver_library => "/data/logstash/postgresql-9.4-1204.jdbc4.jar"
         # The name of the driver class for Postgresql
         jdbc_driver_class => "org.postgresql.Driver"
         jdbc_validate_connection => true
         # our query
         **statement_filepath => "testindex.sql"**
     }
  }

 output{
   elasticsearch{
     action =>"update"
     index => "indexname"
     manage_template => false
     document_id => "%{uid}"
     doc_as_upsert => true
     hosts => ["192.168.56.105"]
   }
 }

注意: statement_filepath => " testindex.sql" testindex.sql有select语句,用于查询postgres中的数据

问题: 当我尝试使用REST API将数据直接插入弹性搜索时,它可以正常工作并插入文档而不会出现任何错误。

**但是当我尝试使用上面的logstash jdbc插件插入文档时,它会给我以下错误。我错过了任何标志或配置参数吗? **

status"=>400, "error"=>{"type"=>"illegal_argument_exception", "reason"=>"Mapper for [expiration_date] conflicts with existing mapping in other types:\n[mapper [expiration_date] is used by multiple types. Set update_all_types to true to update [format] across all types.]"}}}, :level=>:warn}

0 个答案:

没有答案