怎么又是你

从CSV导入文件到ES,设置ID自增不起作用。

匿名 | 发布于2018年09月28日 | 阅读数:4708

我用的是elasticsearch-rtf 5.1, elasticsearch-head 5.1.1, logstash-5.1.1,
然后我要吧CSV的文件导入到ES里面,因为CSV里面没有ID这个column,而且我还不想用系统自带的string类型的_id,所以我就在网站找到一个方法,就是在logstash 的conf文件里面,在output的位置加上document_id => "%{id}",但是,我加了这个之后,不但_id自增不起作用,现在连导入数据都有问题了。
 
 


input {
  file {
    path => ["csv/chinese food.csv"]
    start_position => "beginning"
  }
}
filter {
  csv {
    columns => ["product","price","address","telephone",“contact_name”]
    separator => ","
  } 
  mutate {
    remove_field => ["message","path","host"]
  }
 
}
output {
  elasticsearch {
        hosts => ["localhost:9200"]
        index => "test"
        document_type => "food"
        document_id => "%{id}"
  }
  stdout {}
}


运行这个文件后,
Screenshot_from_2018-09-28_19-25-11.png

test doc显示1(250)
 
然后点进去查看,_id 下面竟然是%{id}

Screenshot_from_2018-09-28_19-27-13.png

这到底是什么原因呢?请大神赐教。
 
另外,还有一个问题,正常导入CSV的时候,会把表格中的第一行header也导入进去,我想问一下,在5.1.1版本中,有没有什么方法去掉CSV的header啊?
谢谢了。
 
 
已邀请:

rochy - rochy_he

赞同来自:

"%{id}" 的意思是你上面的字段里面有一个字段名为:id
你上面没有这个字段,所以没有生效

zqc0512 - andy zhou

赞同来自:

ilter {
  csv {
    columns => ["product","price","address","telephone",“contact_name”]
    separator => ","
  } 
这玩意就是对应每条数据的。没有必要再添加表投。
id问题见楼上。
你可以不要这个ID,让随机生成,看业务需求。

要回复问题请先登录注册