inserting a record to elasticsearch using Springboot Restful service - spring

can any please guide on how to insert record to elastic search using spring boot rest service
we are using spring boot,restful service.
I have tried with elastic document but couldnt get much from it
Have used the below approach but index is not getting created in ES
IndexRequest indexRequest = new IndexRequest("INDEX_NAME", "type", "id")
.source(jsonMap)
.opType(DocWriteRequest.OpType.CREATE);
try {
ActionFuture<IndexResponse> response = client.index(indexRequest);

Related

RestHighLevelClient parameter [include_type_name] with Elastic 8.5.1

iam trying to run spring boot application with RestHighLevelClient 7.17.4 in compatibility mod with elastic 8.5.1 by fallowing guide. When application try to call get, i've got the fallowing error:
Elasticsearch exception [type=illegal_argument_exception, reason=request [/*] contains unrecognized parameter: [include_type_name]]
My configuration of RestHighLevelClient in compatibility mod:
#Value("${hs360.services.watchlist.mgmt.elasticsearch.host}")
private String elsHost;
#Value("${hs360.services.watchlist.mgmt.elasticsearch.port}")
private int elsRestPort;
#Bean(destroyMethod = "close")
public RestHighLevelClient sourceClient() {
return new RestHighLevelClientBuilder(
RestClient.builder(new HttpHost(elsHost, elsRestPort)).setRequestConfigCallback(r -> r.setConnectTimeout(60000).setSocketTimeout(90000)).build()
).setApiCompatibilityMode(true).build();
}
and snippet, when application try to call get:
GetIndexResponse indexResponse = restHighLevelClient.indices().get(new GetIndexRequest().indices("*"), RequestOptions.DEFAULT);
From log of request i can obviously see, that request contains parameter include_type_name
org.elasticsearch.client.RestClient : request [GET http://hs360-ss-s
ource-master:9200/*?master_timeout=30s&include_type_name=true&ignore_unavailable=false&expand_wildcards=open&all
ow_no_indices=true&ignore_throttled=false] returned 1 warnings: [299 Elasticsearch-8.5.1-c1310c45fc534583afe2c1c
03046491efba2bba2 "[ignore_throttled] parameter is deprecated because frozen indices have been deprecated. Consi
der cold or frozen tiers in place of frozen indices."]
I know, that this parameter is deprecated, i though compatibility mod would handle this, but obviously, there is something else. I tried to search for solution, when i can remove parameter from request, but without success.
How could i remove that parameter from request or work around this problem?
You either need to upgrade to Spring Boot 3.0 which supports ES 8.5 or downgrade Elastic to whatever your Spring Boot version supports

How to create and use Ingest pipeline with Spring data elastic search

I need to upload pdf file in elastic search for searching content inside the pdf file. I used ingest pipeline curl APIs through postman it works fine but, i am unable integrate and use in my spring boot project to index and search on pdf file. Can anyone suggest me how to create and use ingest pipeline in spring data elastic search.
for index and document indexing we just annotated on entity class but for ingest pipeline how we use it.
#Document(indexName = "blog", type = "article")
public class Article {
#Id
private String id;
private String title;
#Field(type = FieldType.Nested, includeInParent = true)
private List<Author> authors;
// standard getters and setters
}
I need clarity in spring boot perspective how to configuring ingest pipeline and how to use it in entity class to save the file data to search.
This is not supported in Spring Data Elasticsearch.
And please note that Spring Boot and Spring Data Elasticsearch are different things. Spring Boot can autoconfigure Spring Data Elasticsearch, but that's it

Unable to find "UpdateQueryBuilder" in springframework data 4

I am upgrading spring elasticsearch data from 3.x to 4.2.1. The support of UpdateQueryBuilder is removed from the latest version which earlier I used to construct UpdateQuery from UpdateRequest object of elasticsearch. For example:
return new UpdateQueryBuilder()
.withId(documentId)
.withClass(getDocumentClass())
.withUpdateRequest(updateRequest)
.build();
The new class UpdateQuery doesn't accept UpdateRequest object but only accepts Query. I would prefer to avoid UpdateRequest conversion to Query somehow.
Does anyone have suggestions on how to make UpdateQuery and UpdateRequest work together?
After the change from 3.2.x to 4.0 a year ago Spring Data Elasticsearch does not accept Elasticsearch classes as parameters to the API in order to constantly abstract away Elasticsearch implementation details from the SDE user.
From 4.0 on there is the nested UpdateQuery.Builder class on which you should be able to set all the parameters you did previously on the org.elasticsearch.action.update.UpdateRequest class.

How to configure Redis inbound channel adaptor in Spring integration DSL?

I am trying to set up a caching service using Spring boot/integration. This service has to retrieve data from Redis database every 6 minutes. I have followed this documentation and there is no example for Spring integration DSL.
<int-redis:inbound-channel-adapter id="redisAdapter"
topics="thing1, thing2"
channel="receiveChannel"
error-channel="testErrorChannel"
message-converter="testConverter" />
I have also followed the example mentioned in this StackOverflow page.
#Bean
RedisQueueMessageDrivenEndpoint redisQueueMessageDrivenEndpoint(RedisConnectionFactory redisConnectionFactory, RedisSerializer<?> serializer) {
RedisQueueMessageDrivenEndpoint endpoint =
new RedisQueueMessageDrivenEndpoint("archive.post.publication.queue", redisConnectionFactory);
endpoint.setOutputChannelName("postPublicationChannel");
endpoint.setErrorChannelName("postPublicationLoggingChannel");
endpoint.setReceiveTimeout(5000);
endpoint.setSerializer(serializer);
return endpoint;
}
I have tried examples from various documentation and none of them related to my scenario. Any help is much appreciated?

ElasticsearchJestHealthIndicator : Health check failed when using Jest in spring boot

I'm using Jest at enter link description here in my spring boot application.
Then I created the client with the example code :
JestClientFactory factory = new JestClientFactory();
factory.setHttpClientConfig(new HttpClientConfig
.Builder("http://myhost:9200")
.multiThreaded(true)
JestClient client = factory.getObject();
Everything is fine. I can use this client to do all the queries I want. Happy till now.
Then the problem, when the application starts up, ElasticsearchJestHealthIndicator class is auto-initialized. But the problem is I don't know where to set the config that it will need, so it uses the default value as http://localhost:9200, which leads me to this problem:
WARN [on(2)-127.0.0.1] s.b.a.h.ElasticsearchJestHealthIndicator : Health check failed
io.searchbox.client.config.exception.CouldNotConnectException: Could not connect to http://localhost:9200
at io.searchbox.client.http.JestHttpClient.execute(JestHttpClient.java:70)
at io.searchbox.client.http.JestHttpClient.execute(JestHttpClient.java:60)
Can someone show me how to properly config it , or turn it off ?
A quick search in the reference documentation shows that Spring Boot will configure for you a JestClient (you can just inject it anywhere you need), and that the following configuration properties apply:
spring.elasticsearch.jest.uris=http://search.example.com:9200
spring.elasticsearch.jest.read-timeout=10000
spring.elasticsearch.jest.username=user
spring.elasticsearch.jest.password=secret
See here for more on this.
The Jest client has been deprecated as well, since both Elasticsearch and Spring Data Elasticsearch provide official support for REST clients.
See https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-elasticsearch

Resources