One : What is? elasticsearch,elasticsearch What is the structure in memory

elasticsearch Is a full-text search engine Apache Lucene Search engine for encapsulation , It can be used for full-text search , Structured search and analysis .

elasticsearch Structure in memory :

Data exists in memory in this form , An index is equivalent to a database , A document is equivalent to a table , file id Property unique . Finally, a pair in the domain is specified json To generate keywords , And pass the generated words to the index (index) assembly .

Two : How to integrate

One : Add dependency
<dependency> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency>
<artifactId>spring-boot-starter-test</artifactId> <scope>test</scope>
</dependency> <dependency> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId> </dependency>
ok!! The first problem arises , Version problem

pringboot There is one spring data assembly , It can be used to connect various data sources . Used to connect elasticsearch Yes
spring-data-elasticsearch Update is slow , Its highest version elasticsearch Of 6.x edition .

so, I unified the version as 1.5.9,elasticsearch Version is 2.4.2,ki Version is 4.6.3
<parent> <groupId>org.springframework.boot</groupId>
<version>1.5.9.RELEASE</version> </parent>
 OK, Another question two ,elasticsearch stay java The port of the client is 9300,Restful
Http The port of is 9200,So configuration file application.yml Write in
spring: data: elasticsearch: cluster-nodes:
Two : create object
@Document(indexName = "hello",type = "product") public class product { private
int id; private String name; get.set... }
indexName  Is the name of the index ,type Is the document type , Use both mysql To make a metaphor ,index Equivalent to database name ,type Equivalent to table name

Three : Defining interfaces

Define a proDao Interface ElasticsearchRepository<T, Serializable>

T Class defined for ,Serializable by Integer
public interface proDao extends ElasticsearchRepository<product, Integer>{ }
This is like jpa equally , Ready to eat ,So, Let's have one Controller It's done

Four : write Controller
@RestController public class proController { @Autowired private proDao proDao;
@GetMapping("/add") public void add() { product p = new product(1, " Sunglasses ");; System.out.println(" Added successfully !!"); } }
Write an add product , Take a look at the effect .

Five :kibana Take a look at it

There was no index at first , We need to create one ourselves .

step :Setting-》 take iIndex contains time-based events Of √ cancel -》 Enter your index name -》create

Finally, click Discover, You can see it

  complete controller,controller There are two problems : One : No, query Query method , Two :getAll() Method cannot be resolved to after return json

with swagger test , Others are normal .
@RestController public class proController { @Autowired private proDao proDao;
@GetMapping("/add") public Object add(@RequestParam("id")int
id,@RequestParam("name")String name) { product p = new product(id,name);; return p; } @GetMapping("/delete/{id}") public Object
del(@PathVariable("id")int id) { product p = proDao.findOne(id);
proDao.delete(id); return p; } @GetMapping("/update") public Object
update(@RequestParam("id")int id,@RequestParam("name")String name) { product p
= new product(id, name);; return p; }
@GetMapping("/getone/{id}") public Object getone(@PathVariable("id")int id) {
product p = proDao.findOne(id); return p ; } @GetMapping("/getAll") public
Object getAll() { Iterable<product> all = proDao.findAll(); for (product
product : all) { System.out.println(product); } return all; } }
swagger Interface

  actually , Finally, there should be a question , Why? elasticsearch This search engine will be so fast ????

ha-ha , I'm also working on it !!!!

©2019-2020 Toolsou All rights reserved,
( Essence )2020 year 8 month 13 day C# Basic knowledge windform Realize two color sphere tfrecord How to use the format jmeter-while Summary of controller use Obviously post Why does the request display parameters in the address bar ?STM32 Infrared tracking car Python realization switch method Huawei's limited old rivals benefit the most ? More and more people divide the cake !【JAVA】【 Huawei campus recruitment written examination - Software 】2020-09-09【Python】 read txt file , Gets the specified location data in the specified row [AndroidO] [RK3399] -- GPIO Drive and control mode