2

I use logstash to index data from a database (in this case Postgres) and put it in an Elasticsearch index. This is my config:

input {

    jdbc {
        jdbc_driver_library => "/path/to/driver"
        jdbc_driver_class => "org.postgresql.Driver"
        jdbc_connection_string => "jdbc:postgresql://POSTGRE_HOST:5432/db"
        jdbc_user => "postgres"
        jdbc_password => "top-secret"
        statement => "SELECT id, title, description, username FROM products"
        add_field => [ "type", "product" ]
    }
}

output {
    if [type] == "product" {
        elasticsearch {
            action => "index"
            hosts => "localhost:9200"
            index => "products"
            document_id => "%{id}"
            document_type => "%{type}"
            workers => 1
        }
    }
}

Question: How can I define a mapping for my SQL query, so that e.g. title + description are indexed as text, but user is indexed as keyword data type?

akohout
  • 1,802
  • 3
  • 23
  • 42
  • Logstash doesn't hold mappings instead Elasticsearch indices contains mappings. Here, you need to create `products` index with explicit mappings. – avr May 05 '17 at 20:16
  • The default logstash index template already does this, i.e. the `title` and `description` are indexed as text and the `username.keyword` field is a `keyword`. What do you see when you look at your `products` index using `curl -XGET localhost:9200/products`? – Val May 06 '17 at 04:14
  • How can I create explicit mappings here @avr? – akohout May 07 '17 at 19:04
  • @akohout Hope following link may help you! https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html#_explicit_mappings – avr May 08 '17 at 07:54
  • 1
    Is it possible to do that in the logstash configuration? – akohout May 08 '17 at 18:49

0 Answers0