In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
In this article Xiaobian for you to introduce in detail "how to use python batch import data into Elasticsearch", the content is detailed, the steps are clear, the details are handled properly, I hope this "how to use python batch import data into Elasticsearch" article can help you solve doubts, the following follow the editor's ideas slowly in-depth, together to learn new knowledge.
Give the code first.
# coding=utf-8from datetime import datetimefrom elasticsearch import Elasticsearchfrom elasticsearch import helperses = Elasticsearch () actions = [] f=open ('index.txt') i=1for line in f: line = line.strip (). Split ('') action= {"_ index": "image", "_ type": "imagetable", "_ id": I, "_ source": {u "picture name": line [0] .decode ('utf8'), u "Source": line [1] .decode (' utf8') U "authoritative": line [2] .decode ('utf8'), u "size": line [3] .decode (' utf8'), u "quality": line [4] .decode ('utf8'), u "category": line [5] .decode (' utf8'), u "model": line [6] .decode ('utf8'), u "country": line [7] .decode (' utf8') U "collector": line [8] .decode ('utf8'), u "department": line [9] .decode (' utf8'), u "keywords": line [10] .decode ('utf8'), u "access rights": line [11] .decode (' utf8')}} idecide1 actions.append (action) if (len (actions) = 500): helpers.bulk (es) Actions) del actions [0: len (actions)] if (len (actions) > 0): helpers.bulk (es, actions)
The meaning of each sentence is still very clear. First of all, index.txt is encoded in utf8, so decode ('utf8') needs to be converted into unicode object, and u needs to be added before "picture name", otherwise ES will report an error.
The speed of import is still very fast, more than 2000 records per second.
Read here, this "how to use python batch import data into Elasticsearch" article has been introduced, want to master the knowledge of this article also need to practice and use in order to understand, if you want to know more related articles, welcome to pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.