简体   繁体   中英

Elasticsearch Java High Level Rest client (deprecated) VS Java Client API

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

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      
);

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM