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??
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
You can use following code instead: @Bean public RestHighLevelClient client() { ClientConfiguration clientConfiguration = ClientConfiguration.builder().connectedTo("localhost:9200").build(); return RestClients.create(clientConfiguration).rest(); }
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
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
@@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.
@@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?
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
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
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
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 {
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 .
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
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); }
You are the best in spring boot
Awesome Explanation Basant !!!Thanks!!!
Nice tutorial. You should make a extended course on Udemy
Totally agree with you ! I would definitely buy it !
Awesome man
I am using Spring Boot 2.2.7.RELEASE and Java 8, which version of elastic search we should be using ?
Am not sure about compatible version
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??
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
You can use following code instead:
@Bean
public RestHighLevelClient client() {
ClientConfiguration clientConfiguration = ClientConfiguration.builder().connectedTo("localhost:9200").build();
return RestClients.create(clientConfiguration).rest();
}
Great Video, appreciate your efforts! :)
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
Amazing Tutorial !
Very helpful video< Thanks keep it up
this native search query builder and some methods are deprecated one
so can you please make a another video explaining newer things
Yes buddy i will
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
Didn't get your question
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
Very nice tutorial.
but how can we connect to the datasource to get data in elasticsearch??
Hi Basant can you update this example with new versions of spring boot and elasticsearch...
Yes i will do that
Thank you, brother, you are super
can we connect to the datasource to get data in elasticsearch and perform search operations .. Please tell me @javaTechie
How to manage schema migration in elasticsearch similar to what liquibase does for relational databases?
Nice tutorial. I have a question on how can I add other elasticsearch features such as highlight or autocomplete here?
so there is no need to create indexes?
It's required
But you did not created index or used indexes while fetching from ES.
Amazing video again! Thank you for that! Could you upload a video about parsing a JSON file using spring boot? Thank you!
Sure will do that
can u pls explain with multiple conditions...?
e.g: like, IN/NOT-IN, equal, greaterThan, lessThan etc with a single query..
what is the alternate solution if we don't want to lower spring version
Why jna dependency is required !
Sir how it is done using latest spring version ? I mean full text search ,
Are you getting any issue /error
@@Javatechie actually sir our team is using spring version 2.2.5 , there nodeBuilder not recognised
@@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.
@@Javatechiesir the spring version 1.5.9 is not compatible with Elk 6.5.1(latest) , maven build failing
Please do update your spring boot version
Can make video for JPA projections , JPA transaction and JPA query DSL . please
Will do
@@Javatechie please update soon
Any link for jpa transaction I have to do one POC
I will update tomorrow , could you please remind this on javatechie4u@gmail.com
thanks bhai
Hi ,How to achieve the Facet ,When I search I need to get highlighted,and I need to get the suggestions
hey in the last video why did we not need the config class?
Are you asking in this tutorial
@@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?
Thank you !
Can you please explain how to connect x-pack enabled elastic search from simple console based java application.It would be very grateful..:)
Ok I'll check and let you know
Nice video, I have one doubt. Why you use net.java.dev.jna
It's possible make a "query + aggregations" using Spring data elasticsearch?
Yes we can
@@Javatechie I'm looking for to build a query with aggregation, but I don't find a solution.
Let me check if I can , just share your requirement please
How to enable elastic query logs?
NodeBuilder is deprecated pls make another video using QueryDSL
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
404 means url mismatch so please give proper URL
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
Hi sir ,I am getting status: 500 and nonodeavailableexception throwing sir pls help me sir to solve this pblm
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
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
+ "]";
}
}
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 .
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
Yes it's due to version can you try with lower version or just create an issue in GitHub
How we can use IN/NOT-IN like oracle..?
e.g: fieldName IN ("val1", "val2","val3")
Okay
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());
}
}