Elasticsearch Rest client for Query DSL - elasticsearch

I am trying to write a method using ElasticsearchRestTemplate to fetch data from elasticsearch using query DSL ]. I looked into the documentation, but the documentation is not clear to me how to get the data from elasticsearch using java. Can anyone please help me how to fetch data from elasticsearch using Java client ( ElasticsearchRestTemplate ) by query DSL?

Spring Data Elasticsearch does not support QueryDsl.

Related

Spring Data Elasticsearch with RestHighLevelClient for ES version 6.0.1

We have an application that uses spring data Elasticsearch (version 3.1.20.RELEASE) with transport client to connect to elastic search version 6.1.2.
Now we have to use the same application to connect to elastic search version 6.0.1 which is AWS-managed ES. The problem is, it doesn't seem to expose transport ports (9300) for clients.
If we move to a higher version of spring data Elasticsearch, it doesn't seem to support the elastic search cluster 6.0.x, and the current and lower versions of spring data Elasticsearch don't seem to support the REST clients.
We cannot upgrade our ES cluster version. So, either we have to find a way to connect to AWS with the transport client, or we have to make our application compatible with rest client. How can we solve this?
AWS does not expose the transport port / protocol. So you must use the REST protocol. And for Spring Data Elasticsearch that means version 3.2 at least. But this needs Elasticsearch 6.8. So the only way to use Spring Data Elasticsearch is to upgrade your ES cluster.
The other solution is to implement access the the cluster with Elasticsearch's RestClient and RestHighlevelClient and not using Spring data Elasticsearch

Elastic search high/low rest client vs spring rest template

I am in a dilemma over to use spring's rest template or elasticsearch's own high/low rest client while searching in es . Does es client provide any advantage like HTTP connection pooling , performance while compared to spring rest template . Which of the two take less time in getting response from the server . Can some one please explain this ?
The biggest advantage of using Spring Data Elasticsearch is that you don't have to bother about the things like converting your requests/request bodies/responses from your POJO domain classes to and from the JSON needed by Elasticsearch. You just use the methods defined in the ElasticsearchOperations class which is implemented by the *Template classes.
Or going one abstraction layer up, use the Repository interfaces the all the Spring Data modules provide to store and search/retrieve your data.
Firstly, This is a very broad question. Not sure if it suits the SO guidelines.
But my two cents:
High Level Client uses Low Level client which does provide connection pooling
High Level client manages the marshalling and unmarshalling of the Elastisearch query body and response, so it might be easier to work using the APIs.
On the other hand, if you are familiar with the Elasticsearch querying by providing the JSON body then you might find it a bit difficult to translate between the JSON body and the Java classes used for creating the query (i.e when you are using Kibana console or other REST API tools)
I generally overcome this by logging the query generated by the Java API so that I can use it with Kibana console or other REST API tools.
Regarding which one is efficient- the library will not matter that much to affect the response times.
If you want to use Spring Reactive features and make use of WebClient, ES Libraries do provide support for Async search.
Update:
Please check the answer by Wim Van den Brande below. He has mentioned a very valid point of using Transport Client which has been deprecated over REST API.
So it would be interesting to see how RestTemplate or Spring Data ElasticSearch will update their API to replace TransportClient.
One important remark and caveat with regards to the usage of Spring Data Elasticsearch. Currently, Spring Data Elasticsearch doesn't support the communication by the High Level REST Client API. They are using the transport client. Please note, the TransportClient is deprecated as of Elasticsearch 7.0.0 and is expected to be removed in Elasticsearch 8.0!!!
FYI, this statement has been confirmed already by another post: Elasticsearch Rest Client with Spring Data Elasticsearch

Customize the SOLR Default response to custom Search response

I was working on the POC of accessing the solr via the microservices using spring boot. I am using the Rest template to connect the solr . My query is can we customize the response that solr returns ?.
For Example:
solrUri="http://localhost:8983/solr/microServicesPOC/select?q=:&wt=json"
When we access the above url, the response solr returns has the docuemnts of fields. I need to get the results in the format of my Product pojo.
Snippet:
resEntity = solrConfig.getRestTemplate().exchange(solrUri,HttpMethod.POST,entity , Product.class);
To achieve from the above way of rest template, I need the solr to return response in Product format. Is it possible from SOlr?
I am not using the solrTemplate or the solrJ. I want the customization from the solr side not on the service side .
Tried customizing the searchHandler ,Writing DocTransformer but none of the methods worked .

How do I send Bulk data to elasticsearch using log4j2

I am new to elasticsearch. I need to send bulk data to elasticsearch using log4j2. I didn't find any proper information on the internet for this. Even some informative article would be a great help. Thanks in advance.
NoSql Log4j2 appender logs messages to Elasticsearch.
https://github.com/jprante/log4j2-elasticsearch

Refreshing the ElasticSearch index from RDBMS using Spring Data

I have the following setup :
Mysql RDBMS server
Elastic Search Server
My requirement is to copy data periodically from MYSQL RDBMS and update Elastic server with it.Currently i am following the approach below :
A Batch Job which reads all data from MYSQL using Spring Data Jpa
It then pushes all data to elastic server using spring data elastic
This approach is very cumbersome and not efficient.Is there a way where i can read only the updated values using spring data and update the index accordingly in elastic.
Using jdbc-river etc is not an option for me as the application uses Spring data elastic to get data and search over elastic search,with jdbc-river it will not be able to function properly i think.

Resources