I have problem to push mysql data to elasticsearch using mysql replicator.
I have two table for chat__user and chat_message.
chat_user:
id name socketid
1 raj 123
2 kumar 1234
chat_message:
id chat_from chat_to message
1 123 1235 hello
2 1235 123 how can i help you?
3 123 1235 HOw track my order?
then, John this two tables Using "chat_message.chat_from = chat_user.socketid OR chat_message.chat_to = chat_user.socketid"
Myquery:
SELECT * FROM `chat_message` INNER JOIN `chat_user` ON chat_message.chat_from = chat_user.socketid OR chat_message.chat_to = chat_user.socketid
Result:
chat_from chat_to message id name socketid
123 1235 hello 1 raj 123
1235 123 how can i help you? 1 raj 123
123 1235 HOw track my order? 1 raj 123
If I push this data to elasticsearch, only push last row data.
123 1235 HOw track my order? 1 raj 123
Because Duplication occur in primary key I set primary key chat_user id is a primary key in td-agent configuration file.
Td-Agent Configuration File:
####
## Output descriptions:
##
# HTTP input
# POST http://localhost:8888/<tag>?json=<json>
# POST http://localhost:8888/td.myapp.login?json={"user"%3A"me"}
# @see http://docs.fluentd.org/articles/in_http
<source>
@type http
port 8888
</source>
## live debugging agent
<source>
@type debug_agent
bind localhost
port 24230
</source>
####
## Examples:
##
<source>
@type mysql_replicator
host localhost
username root
password gworks.mobi2
database livechat
query SELECT * FROM `chat_message` INNER JOIN `chat_user` ON chat_message.chat_from = chat_user.socketid OR chat_message.chat_to = chat_user.socketid;
primary_key id
interval 10s
enable_delete yes
tag replicator.history5.histestb.${event}.${primary_key}
</source>
<match replicator.**>
@type stdout
</match>
<match replicator.**>
@type mysql_replicator_elasticsearch
host localhost
port 9200
tag_format (?<index_name>[^\.]+)\.(?<type_name>[^\.]+)\.(?<event>[^\.]+)\.(?<primary_key>[^\.]+)$
flush_interval 5s
max_retry_wait 1800
flush_at_shutdown yes
buffer_type file
buffer_path /var/log/td-agent/buffer/mysql_replicator_elasticsearch.*
</match>
Reference : https://github.com/elastic/elasticsearch/issues/18882
I need to push all data to elasticsearch, Suggest me How to solve this Problem? .