This week I spent some time with ElasticSearch. I thought it would be nice to get a little know-how in case a companies table in my pet project’s database grows up so much that searching for a data will last forever. Well, considering the fact that one of the two most important features in my project is searching, I can’t believe I didn’t think about it earlier!
A few possibilities
There is a few search engines I could use. I was considering a Lucene (but it’s so old… I remember using it about 6 years ago!), Solr (I heard it’s the fastest one) and ElasticSearch (some says it’s aimed for bigger projects). So I decided on ElasticSearch… my project is gonna be huge, right? 😛
I was full of doubts when started to read ElasticSearch tutorials. Everybody I know treats search engines like a stinker and I was sure I will hate it soon too! But you know what? It’s easy and nice. And has a very nice tool named Sense that is an extension to Chrome.
But before playing with all the indexing stuff, let’s read some steps we have to do to start.
1. Download ElasticSearch (from here)
2. Unzip the folder and go to the bin/ catalog.
3. Run cmd here (e.x. by typing cmd in the path part of the window).
4. In console window run elasticsearch.bat
That’s it! That simple! Unless you encounter a problem… Or a pack of them :D. Like I did, of course!
I got the following error in the cmd window:
‘JAVA_HOME environment variable must be set!’
Well, ok, ES uses java, the error message is quite clear. Let’s set this envirnoment variable (ex. this way) and have some fun.
The next error after typing elasticsearch.bat was:
Error: missing `server’ JVM at `C:\Program Files (x86)\Java\jre1.8.0_131\bin\server\jvm.dll’.
Please install or use the JRE or JDK that contains these missing components.
Ooook, but what is going on? Well, I checked if my Java version is up to date. It is. So I go to the path from the error and… Oh! It’s missing! There is no ‘server’ folder!
But wait a minute! There is subfolder ‘server‘ in JDK folder… Yes, you are right, let’s copy subfolder ‘server‘ from JDK location to JRE folder.
Yay! It worked! And… another error!
Error occurred during initialization of VM
Could not reserve enough space for 2097152KB object heap
What the f…? I checked my hard drive free space size. Yep, there is plenty of free space! So what’s the problem?
Well, it took me a while to find a solution because the error message meant nothing…
Smart guys from the Internet suggests that it’s a known problem with an outdated version of java. But hey! I’ve got the newest one! So hey, java? You know I don’t like you, right? And that’s not only because of this evening! So stop playing tricks with me!
After a few long moments I thought that maybe (only maybe!) it’s not java fault and (maybe!) my configuration may be (maybe!) wrong. Rather not! Of course not! But ok, let’s check it. To prove it’s not my fault! At all, really.
Well, I configured here only JAVA_HOME variable so let’s check it! There is no sense in doing it but OK.
Oh, I see it! There is JAVA_HOME variable set to the path with 32-bit java version! Ha! What a noob! Hahaha, OMG haha, oh wait!
Well, that’s a typo, probably will not change anything but let’s set this JAVA_HOME variable to the 64-bit path, like this:
You will never guess!
When you try my solutions you should close the cmd window and reopen it everytime you change anything. I don’t know why but that’s what smart guys from the Internet suggest so it must be something important ;).