What I'm going to mention about is one of the top trending topics on search engineering world, ElasticSearch.
ElasticSearch uses Apache Lucene libraries on its backgorund which allows us to a very high performance, fast, easy to use and easy to implementation opportunities. I will not cover the adv and disadv of the engine. For ones who are interested, here a link is;
https://www.elastic.co/use-cases/stumbleupon
If you are a beginner on ElasticSearch and if you desire to work it on a JAVA project, all you need to do is just adding a few dependencies to your pom.xml of your maven project.
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>1.7.3</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-expressions</artifactId>
<version>4.10.2</version>
</dependency>
If you have any errror while you starting up your server something like:
java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory
java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileItemFactory
org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. Socket read failed
Caused by: java.io.IOException: Socket read failed
All you need to just add two more dependency to pom.xml:<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.1</version>
</dependency>
Then you can feel yourself free for a good starting after updating your maven project.
You can optionally ( Actually this is the best approach ) create yourself a bootstrap.java. The functionality of this bootstrap will be, as usually, while your server is up, your bootstrap will be read for once and will create a node and a client for you.
If you desire to launch your elasticSearch engine into your IDE, you can add following lines into your bootstrap;
Node node = NodeBuilder.nodeBuilder().node();
Client client = node.client();
This will directly creates you a node and a client to work on. Now you can start to index some data into your elasticSearch. After you create your first index, An extra folder will appear in your project hierarcy and will include your node and data information.
However,
If you want that your engine should work seperately than out of your IDE. All you need to do is installing current elasticSearch to your PC from here, then run it under bin/elasticsearch.bat.
Now your engine is up, congrats...
Turn back to your IDE and add following lines to your bootstrap.java
Settings settings = ImmutableSettings.settingsBuilder()
.put("cluster.name", "cluster.value").build();
transportClient = new TransportClient(settings);
TransportClient client = transportClient.addTransportAddress(new InetSocketTransportAddress("127.0.0.1",9300));
Those lines will direct your comments to your seperate elasticSearch engine.
To remind you guys, you should have your elasticsearch.yml file created on \src\main\resources\elasticsearch.yml.
There is no configuration needed to make this file read. Just create a client or a transport client. While creation process it looks under your \src\main\resources\ if there is a config file.
In your elasticsearch.yml file the lines should be:
cluster.name: myCluster-ES
node.name: myNode-01
node.client: true
network.host: 127.0.0.1
After these little code blocks now you are ready to index. But don't forget to stop your client and node after your work is done.
client.close();
node.close();
Have Fun ...
Hiç yorum yok:
Yorum Gönder