Spring Data ElasticSearch using QueryDSL | Java Techie

Поділитися
Вставка
  • Опубліковано 6 лис 2024

КОМЕНТАРІ • 75

  • @waxylayer8353
    @waxylayer8353 3 роки тому +2

    You are the best in spring boot

  • @MohitSaini-tv8go
    @MohitSaini-tv8go 5 місяців тому +1

    Awesome Explanation Basant !!!Thanks!!!

  • @ngalula
    @ngalula 5 років тому +5

    Nice tutorial. You should make a extended course on Udemy

    • @waxylayer8353
      @waxylayer8353 3 роки тому +1

      Totally agree with you ! I would definitely buy it !

  • @Gautam_kumar_200
    @Gautam_kumar_200 Рік тому +1

    Awesome man

  • @prateekashtikar8631
    @prateekashtikar8631 4 роки тому +1

    I am using Spring Boot 2.2.7.RELEASE and Java 8, which version of elastic search we should be using ?

    • @Javatechie
      @Javatechie  4 роки тому

      Am not sure about compatible version

  • @muhammadharisasif1228
    @muhammadharisasif1228 5 років тому +2

    Amazing Job!
    I have one question that why you did not use Spring Boot 2? There is no node builder in the latest elastic version and there is no other way to do the same stuff with the latest elasticsearch and spring boot 2??

    • @Javatechie
      @Javatechie  5 років тому

      Hi Asif , spring boot 2x is not compatible with Elastic Search that's why I used lower version ...
      I googled it but didn't find solution to work with spring boot 2.x with Elastic Search

    • @nirmalsurana2720
      @nirmalsurana2720 2 роки тому

      You can use following code instead:
      @Bean
      public RestHighLevelClient client() {
      ClientConfiguration clientConfiguration = ClientConfiguration.builder().connectedTo("localhost:9200").build();
      return RestClients.create(clientConfiguration).rest();
      }

  • @TheVishnuvnv
    @TheVishnuvnv 2 роки тому +1

    Great Video, appreciate your efforts! :)

  • @vansh1156
    @vansh1156 Рік тому

    Nice video , Sir i want to write fuzzy query in java and not able to write it would you tell me what will be query for it

  • @jyotiranjan5096
    @jyotiranjan5096 3 роки тому +1

    Amazing Tutorial !

  • @atharhussain9223
    @atharhussain9223 4 роки тому +1

    Very helpful video< Thanks keep it up

  • @codesurmay
    @codesurmay Рік тому +1

    this native search query builder and some methods are deprecated one
    so can you please make a another video explaining newer things

  • @rajaprabhu9215
    @rajaprabhu9215 3 роки тому +1

    Elastic search is unstructured right ? for a example in customer documents, one document has five field and another has 9 fields in that case the Customer Model defined in the Java wont fit right ?how to handle such thing pls explain

  • @NishantKumar-vk1ic
    @NishantKumar-vk1ic 3 роки тому

    Amazing Video ... Can you please upload a video on sum and group by with multiple columns in elastic search. That will be a great help. If you have already done, you can share me the link

  • @ShubhamYadav-fl4eb
    @ShubhamYadav-fl4eb 5 років тому +1

    Very nice tutorial.
    but how can we connect to the datasource to get data in elasticsearch??

  • @basappakarlatthe1006
    @basappakarlatthe1006 2 роки тому +1

    Hi Basant can you update this example with new versions of spring boot and elasticsearch...

  • @ravikumar-it1xm
    @ravikumar-it1xm 4 роки тому +1

    Thank you, brother, you are super

  • @udayshankar4780
    @udayshankar4780 4 роки тому

    can we connect to the datasource to get data in elasticsearch and perform search operations .. Please tell me @javaTechie

  • @yashrao7236
    @yashrao7236 3 місяці тому

    How to manage schema migration in elasticsearch similar to what liquibase does for relational databases?

  • @raginikalvade1025
    @raginikalvade1025 3 роки тому

    Nice tutorial. I have a question on how can I add other elasticsearch features such as highlight or autocomplete here?

  • @udyanshardhar1532
    @udyanshardhar1532 4 роки тому +1

    so there is no need to create indexes?

    • @Javatechie
      @Javatechie  4 роки тому

      It's required

    • @udyanshardhar1532
      @udyanshardhar1532 4 роки тому

      But you did not created index or used indexes while fetching from ES.

  • @andreaschristou6952
    @andreaschristou6952 5 років тому +1

    Amazing video again! Thank you for that! Could you upload a video about parsing a JSON file using spring boot? Thank you!

  • @rakeshranjan2798
    @rakeshranjan2798 3 роки тому

    can u pls explain with multiple conditions...?
    e.g: like, IN/NOT-IN, equal, greaterThan, lessThan etc with a single query..

  • @anandkumar-ko5ok
    @anandkumar-ko5ok 4 роки тому

    what is the alternate solution if we don't want to lower spring version

  • @sarojsahoo8763
    @sarojsahoo8763 4 роки тому +1

    Why jna dependency is required !

  • @arghyamitra3281
    @arghyamitra3281 4 роки тому +1

    Sir how it is done using latest spring version ? I mean full text search ,

    • @Javatechie
      @Javatechie  4 роки тому

      Are you getting any issue /error

    • @arghyamitra3281
      @arghyamitra3281 4 роки тому +1

      @@Javatechie actually sir our team is using spring version 2.2.5 , there nodeBuilder not recognised

    • @Javatechie
      @Javatechie  4 роки тому +1

      @@arghyamitra3281 it shouldn't lead any issue
      We might need to add some additional configuration as in each release version spring developer doing configuration changes.

    • @arghyamitra3281
      @arghyamitra3281 4 роки тому +1

      @@Javatechiesir the spring version 1.5.9 is not compatible with Elk 6.5.1(latest) , maven build failing

    • @Javatechie
      @Javatechie  4 роки тому

      Please do update your spring boot version

  • @JitendraSingh.021
    @JitendraSingh.021 4 роки тому +1

    Can make video for JPA projections , JPA transaction and JPA query DSL . please

    • @Javatechie
      @Javatechie  4 роки тому

      Will do

    • @JitendraSingh.021
      @JitendraSingh.021 4 роки тому +1

      @@Javatechie please update soon
      Any link for jpa transaction I have to do one POC

    • @Javatechie
      @Javatechie  4 роки тому

      I will update tomorrow , could you please remind this on javatechie4u@gmail.com

  • @warAlgorithmm
    @warAlgorithmm 4 роки тому +1

    thanks bhai

  • @rappi1597
    @rappi1597 5 років тому

    Hi ,How to achieve the Facet ,When I search I need to get highlighted,and I need to get the suggestions

  • @ashwinraghunath4453
    @ashwinraghunath4453 5 років тому +1

    hey in the last video why did we not need the config class?

    • @Javatechie
      @Javatechie  5 років тому

      Are you asking in this tutorial

    • @ashwinraghunath4453
      @ashwinraghunath4453 5 років тому

      @@Javatechie yes. In this tutorial we made a configuration class and in old elasticsearch tutorial we did not make configuration class and node builder. Why?

  • @armentovmasyan5029
    @armentovmasyan5029 4 роки тому +1

    Thank you !

  • @dbgamer5200
    @dbgamer5200 4 роки тому +1

    Can you please explain how to connect x-pack enabled elastic search from simple console based java application.It would be very grateful..:)

    • @Javatechie
      @Javatechie  4 роки тому

      Ok I'll check and let you know

  • @RaviSavarapu
    @RaviSavarapu 2 роки тому

    Nice video, I have one doubt. Why you use net.java.dev.jna

  • @fabiostrada1510
    @fabiostrada1510 5 років тому +1

    It's possible make a "query + aggregations" using Spring data elasticsearch?

    • @Javatechie
      @Javatechie  5 років тому

      Yes we can

    • @fabiostrada1510
      @fabiostrada1510 5 років тому

      @@Javatechie I'm looking for to build a query with aggregation, but I don't find a solution.

    • @Javatechie
      @Javatechie  5 років тому +1

      Let me check if I can , just share your requirement please

  • @GAneshStudyGAng
    @GAneshStudyGAng 4 роки тому

    How to enable elastic query logs?

  • @rupeshkhade9140
    @rupeshkhade9140 Рік тому

    NodeBuilder is deprecated pls make another video using QueryDSL

  • @mugdha_studyabroad
    @mugdha_studyabroad 5 років тому +1

    sir my program executed .there was a problem in spring suite .but now when I send POST in postman it is giving 404 not found error ./Getindex..please helpppppop

    • @Javatechie
      @Javatechie  5 років тому

      404 means url mismatch so please give proper URL

  • @amitsinha4159
    @amitsinha4159 4 роки тому

    Hello Sir,
    Could you please create a video for below use case, I need your help for below use case. By watching your videos got some clarity on spring data elastic search.
    Use case :-
    Say, We have a movie booking application where I want to fetch the movies in sorted order based on most visited / search movies by user and most visited global movies with out user login.
    For this may need to implement logic to get max score and document wise scores but I am not aware with this how to do in springboot.
    Thanks in Advance

  • @seagull_family4860
    @seagull_family4860 3 роки тому

    Hi sir ,I am getting status: 500 and nonodeavailableexception throwing sir pls help me sir to solve this pblm

  • @kesavulup6829
    @kesavulup6829 5 років тому

    hi sir, when I run the spring boot project then it showing below error
    [Scintilla] failed to get node info for {#transport#-1}{localhost}{127.0.0.1:9300}, disconnecting...
    org.elasticsearch.transport.NodeDisconnectedException: [][127.0.0.1:9300][cluster:monitor/nodes/liveness] disconnected

  • @vijayswaminathan2472
    @vijayswaminathan2472 5 років тому +1

    Thank you for posting this video. However, I am currently facing the following issue when I try to follow your github project. Tried implementing it for a simple department entity. The error that I keep getting is -
    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'departmentController': Unsatisfied dependency expressed through field 'deptService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'departmentService': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query method public abstract java.lang.Object org.springframework.data.elasticsearch.repository.ElasticsearchRepository.index(java.lang.Object)! No property index found for type Department!
    Can you help me with some pointers to resolve this query?
    Sample Code -
    /********** Elastic search repository repository *******************/
    package com.app.mycompany.AgileCenterServices.services;
    import java.util.List;
    import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
    import org.springframework.stereotype.Repository;
    @Repository
    public interface DepartmentService extends ElasticsearchRepository {

    List searchDepartment(String searchQuery);
    }
    /********** JPA repository *******************/
    package com.app.mycompany.AgileCenterServices.repository;
    import org.springframework.data.domain.Page;
    import org.springframework.data.domain.Pageable;
    import org.springframework.data.jpa.domain.Specification;
    import org.springframework.data.jpa.repository.JpaRepository;
    import org.springframework.stereotype.Repository;
    import com.app.mycompany.AgileCenterServices.entities.Department;
    @Repository
    public interface DepartmentRepository extends JpaRepository
    {

    Department findByName(String name);

    Page findAll(Specification spec, Pageable pageable);
    }
    /********** Elastic search configuration *******************/
    package com.app.mycompany.AgileCenterServices.config;
    import java.io.IOException;
    import org.elasticsearch.node.NodeBuilder;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
    import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
    import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
    @Configuration
    @EnableElasticsearchRepositories(basePackages = "com.app.mycompany.AgileCenterServices.services")
    public class EsConfig {

    @Bean
    public NodeBuilder builder() {
    return new NodeBuilder();
    }
    @Bean
    public ElasticsearchOperations elasticsearchTemplate() throws IOException {
    return new ElasticsearchTemplate(builder().local(true).node().client());
    }
    }
    /********** Department entity *******************/
    package com.app.mycompany.AgileCenterServices.entities;
    import javax.persistence.Column;
    import org.springframework.data.elasticsearch.annotations.Document;
    import javax.persistence.Entity;
    import javax.persistence.EntityListeners;
    import javax.persistence.GeneratedValue;
    import javax.persistence.Id;
    import javax.persistence.Table;
    import org.hibernate.annotations.GenericGenerator;
    import org.springframework.context.annotation.Scope;
    import org.springframework.data.jpa.domain.support.AuditingEntityListener;
    @Entity
    @Table(name="department")
    @Document(indexName="department")
    @EntityListeners(AuditingEntityListener.class)
    @Scope("session")
    public class Department {

    @Id
    @GenericGenerator(name = "sequence_department_id", strategy = "com.app.mycompany.AgileCenterServices.util.DepartmentIdGenerator")
    @GeneratedValue(generator = "sequence_department_id")
    @Column(unique = true)
    private String id;

    private String name;

    private String location;

    private String costCenter;

    public Department() {}
    public Department(String id, String name, String location, String costCenter) {
    super();
    this.id = id;
    this.name = name;
    this.location = location;
    this.costCenter = costCenter;
    }
    public String getId() {
    return id;
    }
    public void setId(String id) {
    this.id = id;
    }
    public String getName() {
    return name;
    }
    public void setName(String name) {
    this.name = name;
    }
    public String getLocation() {
    return location;
    }
    public void setLocation(String location) {
    this.location = location;
    }

    public String getCostCenter() {
    return costCenter;
    }
    public void setCostCenter(String costCenter) {
    this.costCenter = costCenter;
    }
    @Override
    public String toString() {
    return "Department [id=" + id + ", name=" + name + ", location=" + location + ", costCenter=" + costCenter
    + "]";
    }

    }

    • @Javatechie
      @Javatechie  5 років тому

      Did you follow Same what I did in this tutorial ?
      It would be more helpful if you add your code in Github and share link here so that I can check it out .

  • @ravisharma3275
    @ravisharma3275 4 роки тому

    I followed your tutorial thoughrouhy but at the time of running the program it's showing application couldn't start i think because of version changing of my spring boot can you tell me any alternative so that i can get rid of this my version is 2.2.4

    • @Javatechie
      @Javatechie  4 роки тому

      Yes it's due to version can you try with lower version or just create an issue in GitHub

  • @rakeshranjan2798
    @rakeshranjan2798 3 роки тому

    How we can use IN/NOT-IN like oracle..?
    e.g: fieldName IN ("val1", "val2","val3")

  • @javokhirnarzullayev
    @javokhirnarzullayev 3 роки тому +1

    Okay

  • @sadhanapriyadarshini9826
    @sadhanapriyadarshini9826 3 роки тому +1

    With Spring Boot 2 there is some changes required :
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.data.elasticsearch.core.SearchHits;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RestController;
    @RestController
    public class QueryDSLController {

    @Autowired
    private QueryDSLService service;
    @GetMapping("/serachMultiField/{firstname}/{age}")
    public SearchHits serachByMultiField(@PathVariable String firstname, @PathVariable int age) {
    return service.searchMultiField(firstname, age);
    }
    @GetMapping("/customSearch/{firstName}")
    public SearchHits getCustomerByField(@PathVariable String firstName) {
    return service.getCustomerSerachData(firstName);
    }
    @GetMapping("/search/{text}")
    public SearchHits doMultimatchQuery(@PathVariable String text) {
    return service.multiMatchQuery(text);
    }

    }
    -----------------------------------
    import org.elasticsearch.index.query.MultiMatchQueryBuilder;
    import org.elasticsearch.index.query.QueryBuilder;
    import org.elasticsearch.index.query.QueryBuilders;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
    import org.springframework.data.elasticsearch.core.SearchHits;
    import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
    import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
    import org.springframework.stereotype.Service;
    @Service public class QueryDSLService {

    @Autowired private ElasticsearchRestTemplate template;

    public SearchHits searchMultiField(String firstname, int age) {

    QueryBuilder query = QueryBuilders.boolQuery().must(QueryBuilders.matchQuery("firstname", firstname))
    .must(QueryBuilders.matchQuery("age", age));

    NativeSearchQuery nativeSearchQuery = new NativeSearchQueryBuilder().withQuery(query).build();
    SearchHits customers = template.search(nativeSearchQuery, Customer.class);
    return customers;
    }
    public SearchHits getCustomerSerachData(String input) {
    String search = ".*" + input + ".*";
    NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
    .withFilter(QueryBuilders.regexpQuery("firstname", search)).build();
    SearchHits customers = template.search(searchQuery, Customer.class);
    return customers;
    }
    public SearchHits multiMatchQuery(String text) {
    NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(QueryBuilders.multiMatchQuery(text)
    .field("firstname").field("lastname").type(MultiMatchQueryBuilder.Type.BEST_FIELDS)).build();
    SearchHits customers = template.search(searchQuery, Customer.class);
    return customers;
    }
    }
    ----------------------------------------------
    import org.elasticsearch.client.RestHighLevelClient;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.data.elasticsearch.client.ClientConfiguration;
    import org.springframework.data.elasticsearch.client.RestClients;
    import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
    import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
    import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;

    @Configuration
    @EnableElasticsearchRepositories(basePackages = "com.subrat.ELK.repository")
    public class EsConfig {


    @Bean
    public RestHighLevelClient client() {
    ClientConfiguration clientConfiguration
    = ClientConfiguration.builder()
    .connectedTo("localhost:9200")
    .build();
    return RestClients.create(clientConfiguration).rest();
    }
    @Bean
    public ElasticsearchOperations elasticsearchTemplate() {
    return new ElasticsearchRestTemplate(client());
    }

    }