简体   繁体   English

使用 python 连接 kafka 和 elasticsearch

[英]connection between kafka and elasticsearch using python

I'm new about using Kafka and elasticsearch.我是使用 Kafka 和 elasticsearch 的新手。 I've been trying to use Elastic search but I've some problem.我一直在尝试使用弹性搜索,但我遇到了一些问题。 I've grow up a docker compose file with all the images needed for building the environment then using kafka I've product into a specific topic the data and then I need to take from Kafka 's consumer data into a pub/sub system for sending data for the ingestion into elasticsearch.我已经长大了一个 docker 组合文件,其中包含构建环境所需的所有图像,然后使用 kafka 我已经将数据产品放入特定主题,然后我需要从 Kafka 的消费者数据中获取 pub/sub 系统将摄取数据发送到 elasticsearch。 I implement all this using python.我使用 python 实现了所有这些。 I've seen that into the port and localhost as ip elasticsearch appear instead for kibana in the page appear the following sentence: kibana server is not ready yet我已经看到进入端口和本地主机为 ip elasticsearch 代替 kibana 在页面出现以下句子:kibana server is not ready yet

the consumer python is something similar to it from which I take data from a topic:消费者 python 类似于我从一个主题中获取数据的东西:

from kafka import KafkaConsumer
# Import sys module
import sys

# Import json module to serialize data
import json

# Initialize consumer variable and set property for JSON decode
consumer = KafkaConsumer ('JSONtopic',bootstrap_servers = ['localhost:9092'],
value_deserializer=lambda m: json.loads(m.decode('utf-8')))
for message in consumer:
 print("Consumer records:\n")
 print(message)
 print("\nReading from JSON data\n")
 print("Name:",message[6]['name'])
 print("Email:",message[6]['email'])
 # Terminate the script
 sys.exit()

The goal is to use elasticsearch for doing analysis so I need to use it as backend as for visualize data into kibana.目标是使用 elasticsearch 进行分析,因此我需要将其用作后端,以便将数据可视化到 kibana 中。 It could be really appreciate also a tutorial to follow for understanding what I should do for link this informations.也非常感谢一个教程来理解我应该做什么来链接这些信息。 (Ps data follow without problem from a topic to another one but the problem is to take this information and insert into elastic and have the possibility to visualize these informations) (ps数据从一个主题到另一个主题没有问题,但问题是获取这些信息并插入弹性并有可能将这些信息可视化)

If you're pushing data from Kafka to Elasticsearch then doing it with the Consumer API is typically not a good idea, since there are tools that exist that do it much better and handle more functionality.如果您要将数据从 Kafka 推送到 Elasticsearch,那么使用消费者 API 通常不是一个好主意,因为存在一些工具可以做得更好并处理更多功能。

For example:例如:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM