Spring boot integrates elasticsearch to realize case analysis of full-text search engine

In short, ElasticSearch (ES) is a search engine and a distributed search engine for structured data. Elastic search is an open-source, distributed, real-time search and analysis engine. Spring boot provides basic configuration for the abstractions provided by elastic search and spring data elastic search. Spring boot provides a spring boot starter data elastic search for aggregating dependencies 'StarterPOM'。

Spring boot starter data elastic search dependency is introduced in POM The following contents are added to the XML configuration file (based on the pom.xml file in the previous chapter "spring boot construction framework"):

You can inject an automatically configured elasticsearchtemplate or elasticsearch client instance like other spring beans. By default, the instance will try to connect to a local memory server (a nodeclient in the elasticsearch project), but it can be switched to a remote server (such as transportclient) by setting spring.data.elasticsearch.clusternodes to a comma separated host: port list.

If you add a @ bean of your own elasticsearchtemplate type, it will replace the default.

Application integration elasticsearch case

Create a new elasticsearch Properties configuration file, add the following configuration contents:

Elasticsearch configuration, read elasticsearch The specific code of the properties configuration file is as follows:

Two entity classes, with specific codes as follows:

The data source inherits elasticsearchrepository class, and the encapsulated interface code is as follows:

Data service interface and implementation class, code as follows:

The test code is as follows:

summary

The above is what Xiaobian introduced to you. Spring boot integrates elasticsearch to realize the case analysis of full-text search engine. I hope it will be helpful to you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>