我在我的项目中使用elasticsearch,并且我要求使用Elasticsearch JDBC River插件将大型MySQL数据拖入Elasticsearch。我需要将mysql表同步到elasticsearch,所以我正在为jdbc河流索引创建一个映射。
curl -XPOST http://localhost:9200/city -d '
{
"mappings" : {
"city_type": {
"properties" : {
"domain" : {
"type" : "multi_field",
"fields" : {
"domain" : {
"type" : "string",
"index" : "analyzed"
},
"exact" : {
"type" : "string",
"index" : "not_analyzed"
}
}
},
"sent_date" : {
"type" : "date",
"format" : "dateOptionalTime"
}
}
}
}
}'
在elasticsearch中创建映射后。我想将mysql表数据加载到其中。所以我使用以下命令。
curl -XPUT 'localhost:9200/river/city/_meta?pretty' -d '{
"type" : "jdbc",
"jdbc" : {
"url" : "jdbc:mysql://localhost:3306/test",
"user" : "root",
"password" : "root",
"sql" : "select id as _id,id as domain from city;",
"strategy":"oneshot"
},
"index" :{
"index" : "city",
"type" : "city_type",
"bulk_size":500
}
}'
这些查询成功运行,当我运行命令查找elasticsearch中的数据为空时,在这些查询之后。
http://localhost:9200/river/_search?pretty&q=*
请检查上述查询here的回复。为什么数据没有显示在elasticsearch查询中请帮助。
答案 0 :(得分:0)
顺便说一句,River已被弃用https://github.com/elastic/elasticsearch/issues/10345。
我强烈推荐jprante jdbc importer,这是一个java独立的,允许你做你需要的操作。 https://github.com/jprante/elasticsearch-jdbc。它并不完全是一条河,因为你定义了一条河。
关于你的问题,请你试试http://localhost:9200/_search?pretty&q= *?使用语法,您实际上是在索引河中查找数据。您应该使用我编写的查询或城市索引查看所有索引:http://localhost:9200/city/city_type/_search?pretty&q= *
答案 1 :(得分:0)
如果我在你的位置,我会使用logstash将数据从MySQL推送到Elastic。很久以前,River已被弃用,因为@Artholl已经提到过。