1. Download ElasticSearch
Net official download link: https://www.elastic.co/cn/downloads/past-releases (go may be slower, Network good situation will be better)
I was under the version is 7.0.3, and 5.6.8 have compared the windows very different, including some of the attributes of what methods, so be careful! weight! selected! Optional!
2. Run ElasticSearch
After it is finished, unzip to where you want to unpack, open the bin
Click on the first one, will show a bunch of boot log,
Show started on ok,
In the browser address bar enter http: // localhost: 9200
This explains ElasticSearch display to successfully install it, turn off the startup of elasticsearch Terminal Services Mac: Ctrl + c.
3. Install node
Used here is homebrew
brew install node
Wait until the installation is complete, there should not be any hole, if the download fails you can turn off the terminal repeated several times (the network itself), with a time of npm install homebrew node is a default component will be installed, and comes with a Bahrain nodejs npm.
Then, enter homebrew
git clone git://github.com/mobz/elasticsearch-head.git
The cloned into local mirroring, after the end of input into the catalog
elasticsearch- cd head
npm install
npm install -g Grunt-cil // If unsuccessful before
After implementation, modification elasticsearch profile: elasticsearch.yml, add the following two commands:
http.cors.enable:true http.cors.allow-origin:"*"
This step is to allow access across elasticsearch.
After the completion of re-entering the head, enter at the command prompt:
grunt server
This display can be at http: visit friends 9100: // loaclhost
Create a new maven project, import the jar package
1 <dependency> 2 <groupId>org.elasticsearch</groupId> 3 <artifactId>elasticsearch</artifactId> 4 <version>7.3.0</version> 5 </dependency> 6 <dependency> 7 <groupId>org.elasticsearch.client</groupId> 8 <artifactId>transport</artifactId> 9 <version>7.3.0</version> 10 </dependency> 11 <dependency> 12 <groupId>org.apache.logging.log4j</groupId> 13 <artifactId>log4j-to-slf4j</artifactId> 14 <version>2.9.1</version> 15 </dependency> 16 <dependency> 17 <groupId>org.slf4j</groupId> 18 <artifactId>slf4j-api</artifactId> 19 <version>1.7.24</version> 20 </dependency> 21 <dependency> 22 <groupId>org.slf4j</groupId> 23 <artifactId>slf4j-simple</artifactId> 24 <version>1.7.21</version> 25 </dependency> 26 <dependency> 27 <groupId>log4j</groupId> 28 <artifactId>log4j</artifactId> 29 <version>1.2.12</version> 30 </dependency>
新建class
import java.io.IOException;
import java.net.InetAddress;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
public class test { public static void main(String[] args) throws Exception { //1、创建es客户端连接对象 TransportClient client = new PreBuiltTransportClient(Settings.EMPTY). addTransportAddress(new TransportAddress(InetAddress.getByName("127.0.0.1"), 9300)); //2、创建文档内容 XContentBuilder builder = XContentFactory.jsonBuilder() .startObject() .field("id",1) .field("title","elasticsearch是一个基于lucene的搜索服务") .field("content","ElasticSearch是一个基于Lucene的搜索服务器。" + "It provides a distributed multi-user capabilities of full-text search engine, based on RESTful web interfaces." + "Elasticsearch is written in Java, and as open source under the Apache license terms released," + "is the popular enterprise-class the search engine is designed for the cloud, to achieve real-time search, stable, "+" reliable, fast and easy to install. " ) .endObject (); // 3, the establishment of the document object client.prepareIndex (" blog1 ", "Article This article was", ". 1") setSource (Builder) .get ();. // . 4, release resources client.close (); } }
Run, in the open http: // localhost: 9100,
Such is the success of you, if you still do not show the words:
1. Check the first jar package and import their own elasticsearch versions are the same,
2. Look maven dependencies there is no full
~~~~~~~~·~~~~~~~~·~~~~~~~~·~~~~~~~~·~~~~~~~~·~~~~~~~~·~~~~~~~~·~~~~~~~~·~~~~~~~~·~~~~~~~~·~~~~~~~~·~~~~~~~~·~~~~~~~~