3

I am new to ElasticSearch and with our team we are developing a spring-boot application which communicates with an elasticsearch server. Actually the aim of the application is to map rest methods exposed by Elasticsearch in order to call the ES server from a Controller class with postman...

I've seen there is a brand new Java Client Api 8.4, but I cannot find in the documentation how to delete an indexed document for example. It seems that the Java Client Api is not such complete as the Rest Client Api.

So question is: what's the difference beetween Java Rest Client a Java Client API? which one should I use? I know High level client is deprecated but as I mentioned I don't know how to call methods such as Delete By Query for examle...

I know also there is spring data elastic search for spring-boot but I would use the Java cliet which allows to work with raw json format

Thanks, Saverio

2 Answers 2

2

ElasticsearchClient has a delete() api (see javadoc) to remove documents from indexes and usage of it is not so different than the others.

For eg:

DeleteRequest request = DeleteRequest.of(i -> i.index("your-index").id("document-id"))
DeleteResponse<Product> response = client.delete(request);

should work.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I was getting there too but happy to see someone else which confirm the thing
1

Tldr;

The java API client documentation is purposefully short. On purpose it seems as it is already described in the main documentation of elasticsearch.

For a full reference, see the Elasticsearch documentation and in particular the REST APIs section. The Java API Client follows closely the JSON structures described there, using the Java API conventions.

Solution

Delete by query

It would most likely be like a search query by with a different function name instead.

SearchResponse<Product> response = esClient.search(s -> s // delete_by_query ?
    .index("products") 
    .query(q -> q      
        .match(t -> t   
            .field("name")  
            .query(searchText)
        )
    ),
    Product.class      
);

1 Comment

Many thanks! I got to the same conclusion by reading the documentation. But I am happy to find someone who confirm my hypothesis

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.