Elasticsearch application under the Spring Boot project

Source: Internet
Author: User

Here is the version of elasticsearch2.4.4 that is downloaded

Elasticsearch-head-master

Https://github.com/mobz/elasticsearch-head

Modify a file

Double-click such as Bat

HTTP://192.168.2.104:9200/_PLUGIN/HEAD/,192.168.2.104 is the native IP that was just configured in the configuration file

You can also generate the win service directly

Maven adds the following jar package

 <dependency> 
<groupid>org.springframework.boot</groupid>
<artifactId> Spring-boot-starter-data-elasticsearch</artifactid>
<version>1.5.1.release</version>
</dependency>
Add a profile for ES
 @Configuration @enableelasticsearchrepositories (basepackages = "    Com.example.demo.dao ") public class Esconfig {@Value (" ${elasticsearch.host} ") Private String eshost;    @Value ("${elasticsearch.port}") private int esport;    @Value ("${elasticsearch.clustername}") Private String esclustername;                @Bean Public Client Client () throws Exception {Settings essettings = Settings.settingsbuilder ()        . put ("Cluster.name", Esclustername). Build (); https://www.elastic.co/guide/en/elasticsearch/guide/current/_transport_client_versus_node_client.html return Transportclient.builder (). Settings (essettings). Build (). addtransportaddress    (New Inetsockettransportaddress (Inetaddress.getbyname (eshost), esport)); } @Bean Public Elasticsearchoperations elasticsearchtemplate () throws Exception {return new Elasticsearchtem    Plate (client ()); }

  

This must and ES configuration file inside is corresponding or will error, port number default is this.

Here is the index and type of the configuration

The following creates an interface extension es JPA, where basic additions and deletions are implemented

 Public Interface extends Elasticsearchrepository<esproduct, string> {    esproduct Save (esproduct esproduct);     /*      *     * @author:   wangchao     * @date:     2017/9/22     * @methodName:     Paging Data     * @param Null     * @return         */    Page<EsProduct> findbylocationname (String LocationName, pageable pageable);}

The following is a simple query implemented by ID
@GetMapping ("/search") public responseentity<esproduct> Getsearch (@RequestParam ("id") String ID) { esproduct Esproduct=uzaiproductservice.findone (ID); return new Responseentity<esproduct> (Esproduct, Httpstatus.ok); }

The curd of ES is realized by this basic spring boot.

Elasticsearch application under the Spring Boot project

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.