Elasticsearch Complete Tutorial With Python|Search Elasticsearch Index Using Python|Tutorial:3

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] [Music] what's up guys this is roni welcome back to our channel total technology this is tutorial 3 and today's topic will be how to search elasticsearch index using python so in the last tutorial we have uh we have seen how to create index how to create index in bulk and after that how to uh do some sort of like uh um what do you say like how to see all the indexes like using some star or some aesthetics but that is not the proper use case in this tutorial we will learn how to search index whether this is available or not and how to know that okay so again uh as promised i'll be going to run through the slides now so the first slide will be uh introduction to elasticsearch again i have copy pasted this thing from the elasticsearch official documentation so i'm not going to explain this again so what i'll do i'll just uh give you guys some sort of uh like hint that if you want to learn and explore more on the elastic search thing then probably you can just go back to the official documentation there everything will be there like from the theoretical concept and it is actually very much useful so i'll highly recommend that okay so maybe next thing is going to be the installation so installation steps are like this like from this url and this url you have to download elasticsearch and kibana that will be a zip file after that you have to unzip it and from there you have to run the executable from the bin folder that's it simple once this is done everything is completed but again uh this is going to be a non-secure mode like you don't need to use any user id and password and you can access your elastic search from 9200 and kibana using five six zero one but if you want to enable some sort of security then probably you have to uh go through this link enable manual security actually what it will give you it will give you the steps to enable user id and password authentication so also uh useful that you should not get any warning messages whenever you are trying to connect from your python client so that is why this is also going to be very useful okay and next thing is going to be the what is index and other things i'm not gonna do that and yes that is the thing with the second line i'm using just uh host and port name see you can see here but if you remember in the last tutorial which is tutorial number two in that tutorial we have uh you you have used some sort of user id and password so if someone is new to this uh playlist and directly watching this tutorial number three then probably it will be good if you guys can go ahead and start watching the tutorial from tutorial number one because that will be really useful and you will not miss any any of this concept okay so all theoretical parts are done i know you guys are now kind of very much uh anxious or excited so maybe i can see you so if you see here uh uh like how to access this kibana thing so let me just do it one more time so if i hit this thing uh so it will directly open this thing and after that just go to here and click on the dev tools and you will see this query get cat indexes it will list on all the indexes so you have you will see there are multiple indexes now your requirement is to check whether there is any index with this hr name is present or not how to do that so that will do now okay so let me open my visual studio code okay so now i'll start writing the code so maybe uh maybe i can just give a name to this name to this tutorial probably i'm thinking what will be the best thing to give okay maybe i can write a search elastic search index okay okay okay that's it um okay fine next thing is going to be uh this is done now let me write the connection thing the probability is going to be elastic search okay then this is going to be something like this then host is going to be localhost and here this is going to be port and this is going to be uh maybe 9200 so this is done so now next thing will be http authentication so http authentication means you have to give your user id and password okay so something like this okay and after that you have to use the user id and password elastic will be my user right elastic and password is going to be this one so i copy paste it over here okay and how actually i got this thing so let me just go through this slide so when you open this url it will explain you how to set your own password so everything is documented and over there and it is very very uh neat and clean so everyone will be able to understand it still you guys are having any difficulties or uh like like you guys are facing any problem then definitely let me know i can fix it okay so this is done now just to check okay what happened now to check if my connection is working fine you have to just do a simple step so this is going to be yes on things so this is uh these things are already uh discussed in our earlier tutorial multiple times so hopefully this not been this should not be an issue okay so then how to run it's going to be python 3 and after that tutorial 3 dot py so you will get a true okay and just evaluate our point again same thing whatever i did in the last week so i just changed the password with the qq which is now became invalid so it should return false see verify the elastics of security privileges it means that we have given the invalid password okay so let's see fine so now we'll search something search spacey fig index okay we would like to check whether a specific index is available or not so maybe i can check let's say index is hr so if you see i have an index name called hr i'll check whether this index is available or not okay so simple thing so response is going to be uh yes dot indices dot maybe oh sorry it should be search and there actually i need to pass the index and the index will be index okay so let's see what is actually it is going to be written then we will discuss how to fix it okay so now i'm just going to uh print the raw response okay nothing no parts or nothing okay so see uh one is total is one means i have my total uh one number of instance found okay so now let's say i change it to hr okay so if you check here there is no instance with hr so it should return something with an error let's see what it is actually going to return see it is actually throwing some exception it's elastic search exception not sound error so maybe i need to do something inside this tri-catch block okay maybe uh something like this okay and accept exception fv and then maybe i can print str let's see how it is now going to react see not found error index not found so if the index is not found we'll get an exception if indus is found we'll get like the acknowledgement so something uh like this see i got this thing okay so uh this is going to be a successful in total hit one you will get something like this okay so let's try out something uh to get this thing so it should be response then underscore shirts like this and after that maybe i can write total where it is yeah this total this this is going to work let's see see it means one number of instance has been found okay so this is one thing so let's understand this so we'll have search with a specific index and that index is kind of a hard coded okay so now the requirement is that uh you want to use some sort of rejects that probably um the good thing is that you have created a specific index for a month of october now uh in october 30th uh midnight your your company uh probably uh october 31st midnight your company wants to remove all the last month index and create a new index from november so october 1 october 2 and up to october 35 should be deleted so so before deleting that maybe you want to develop a script which will go and check how many indexes are actually available with the october okay so how to do how to do that so uh you have to use some sort of rejects and this is going to be very simple rejects okay so maybe some sort of pattern so maybe i can do something search index based on pattern okay so let's do something uh maybe we just commented this lines so later on we will we will try to uncomment this thing okay so what i'll do now maybe i can do something let's say let's try again okay so response is going to be yes dot search so this is going to be es not ex and index equals to and here we'll create a pattern so index is going to be let's say october underscore so why i'm saying that see my pattern is october underscore so i'd like to search this thing and after that it could contain anything okay so let's put this thing over here index equals to index okay and let's say print and here probably i can do this thing so it will uh give me the number of indexes like count okay and after that probably i can type accept exception as we like this and then probably print str e so see uh in the last tutorial we have created total 10 index with october october 1 2 3 4 5 6 7 8 9 and 10 so it should return ideally 10 over here so this line should print a 10 so let's see how to do that so maybe i can clear this thing and execute see 10 okay so this is very simple this is like very easy to do it so hopefully you guys will be able to now understand what is required so if you have a complex uh pattern matching then also possible using uh some sort of rejects so regex you uh like elasticsearch rejects and pattern matching for doing some advanced search will be done in the next tutorial okay because this is going to be some sort of intermediate tutorial so i thought that to set up the base or kind of a background or so that you guys can develop your intuition towards this search sort of thing and do some sort of homework before the next tutorial so that is why i just created this small use case so that you guys will be able to understand so now you can do some sort of practice as well to increase the complexity of this pattern as well so if you are not able to do fair enough that is absolutely fine i'm gonna do it in the next tutorial but for this tutorial just keep it like this and hopefully in the next tutorial we'll be going to do some sort of advanced uh thing okay so yeah that's it so let me uncomment this lines okay so yeah so all done so hopefully in the next tutorial uh we'll be able to uh do the other things as well okay so just one request like last time please uh do share some feedback how you guys are enjoying this course whether it is really meeting your expectation or still something is uh lacking if you if you want to me to include something else please write me and let me know how good i can uh um design this course so that it will be beneficial for you because ultimately i am doing this for all of you so if you guys are not getting the benefit then my objective is not going to make so please feel free to put some sort of comment good or bad or feedback it doesn't matter but it has to be honest feedback if you are think if you are thinking that something is missing please let me know i'll try to incorporate all this thing and also if you guys are having any complex use case where actually you need some sort of help please put that in the comment box so probably i can uh create a tutorial on that so hopefully in the intermediate uh like uh section i will do it but that will start maybe after one month or two months after we finish all the basics component exploration okay so that's it guys uh we'll see you in the next video till then take care goodbye and have a nice day and please do some practice or else you will forget okay okay guys one more time have a nice day have a nice weekend we'll see you in the next video till then take care goodbye and happy learning [Music]
Info
Channel: Total Technology
Views: 81
Rating: undefined out of 5
Keywords: elasticsearch, elk stack, elasticsearch automation with python, elasticsearch with python, elasticsearch complete tutorial with python, How To Create Elasticsearch Index In Bulk using python, How To Create Elasticsearch Index In Bulk from file using python, How to Search Elasticsearch Index Using Python
Id: uzBf7Ue4RTE
Channel Id: undefined
Length: 15min 46sec (946 seconds)
Published: Fri Oct 22 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.