0

背景: 我正在尝试将 Postgres 中的数据索引到弹性搜索中,并执行以下步骤:

第 1 步:- 使用logstash jdbc-input插件从 Postgres 批量导入数据。第 2 步:- 使用弹性搜索 REST API(用于 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 有从 postgres 查询数据的 select 语句

问题: 当我尝试使用 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}
4

0 回答 0