使用Logstash将数据从Postgres上传到Elastic Search时出现问题

时间:2019-07-17 20:48:28

标签: postgresql elasticsearch logstash logstash-jdbc

我在Postgres中有一个表,尝试使用Logstash作为中介将其上载到ElasticSearch。我的.conf文件如下所示:

# file: simple-out.conf
input {
    jdbc {
        # Postgres jdbc connection string to our database, mydb
        jdbc_connection_string => "jdbc:postgresql://localhost:32775/postgres"
        # The user we wish to execute our statement as
        jdbc_user => "postgres"
    jdbc_password => "password"
        # The path to our downloaded jdbc driver
        jdbc_driver_library => "/Users/username/Desktop/postgresql-42.2.6.jar"
        # The name of the driver class for Postgresql
        jdbc_driver_class => "org.postgresql.Driver"
    #scheduler
    schedule => "*/10 * * * * *"
        # our query
        statement => "SELECT * from table"
    }
}
output {
    elasticsearch {
        index => "test"
        document_id => "%{id}"
        hosts => "localhost:9200"
    template => "mapping.json"
    template_name => "default_mapping"
    }
}

我为我的表指定一个大致如下的映射:

{
  "mappings": {
    "test": {
      "properties": {
        "id": {
          "type": "keyword",
          "index": "false"
        },
        "some_other_value": {
          "type": "keyword",
          "index" : "false"
        },
        "field1": {
          "type": "completion"
    },
        "field2": {
          "type": "completion"
      },
        "field3": {
          "type": "keyword",
          "index" : "false"
        },
        "field4": {
          "type": "integer",
          "index":"false"
        },
        "field5": {
          "type": "completion"
      },
        "field6": {
          "type": "text",
          "analyzer": "standard"
        },
        "field7": {
          "type": "completion"
        }
      }
    }
  }
}

然后我使用conf执行日志存储,并且运行良好(提示中没有错误)。但是,当我尝试使用Elastic Search的建议语法获取建议时,如下所示:

{
    "suggest": {
        "suggestion1" : {
            "prefix" : "tex", 
            "completion" : { 
                "field" : "field7" 
            }
        }
    }
}

我收到此错误:     “ reason”:“字段[content]不是完成建议

我已经明确指定该字段为内容字段,但是当我从Elastic Search下拉映射时,它被映射为文本字段。为什么弹性搜索不遵守该映射?

0 个答案:

没有答案