I am migrating a java application from elastic search high level client to java api client.
There is a range query like this in the code.
QueryBuilders.rangeQuery("startDate").lte(dateUtils.today())
Need to change this to java api client code.
Could someone help on this?
https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/searching.html
Query dateRangeQuery = RangeQuery.of(r -> r
.field("startDate")
.lte(dateUtils.today())
)._toQuery();
Related
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.
In the microsoft documentation you can see the following example:
graphClient.teams(teamId)
.buildRequest()
.patch(team);
but what happens if the operation is not performed correctly and I want to query the error returned, is there any way to know if the operation failed and get the cause of the error?
I'm not familiar with Java but for .NET you can send HTTP request and read a response status code.
There should be similar way for JAVA.
I am using Google Cloud Translate v3 API Java Client. The Java Client code samples work great. The authentication of the code samples is done using the GOOGLE_APPLICATION_CREDENTIALS environment variable.
I need to develop code that will run in an application server that I have no control over the environment variables. So I need to use another way to get the call authenticated.
Setting Up Authentication for Server to Server Production Applications, under "Passing the path to the service account key in code" has a code sample (choose the JAVA tab) that works for the Storage service, but I can't find a similar way to pass the GoogleCredentials to Translation v3 API Java Client. Does anyone know?
Also, I can't find the Java doc for v3 API. https://googleapis.dev/java/google-cloud-clients/latest/index.html shows version "0.119.0-alpha" and it does not list the package com.google.cloud.translate.v3. Is there a separate java doc page ?
I think I found a solution.
The client API javadoc doesn't list com.google.cloud.translate.v3 but it does list com.google.cloud.translate.v3beta1. In the javadoc for TranslationServiceClient, i.e. https://googleapis.dev/java/google-cloud-clients/latest/com/google/cloud/translate/v3beta1/TranslationServiceClient.html
there's a mention of setting credential, and this method worked!
TranslationServiceSettings translationServiceSettings =
TranslationServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
TranslationServiceClient translationServiceClient =
TranslationServiceClient.create(translationServiceSettings);
Has anyone had any luck using the latest breeze.java.server code from https://github.com/Breeze/breeze.server.java in conjunction with the latest client BreezeJS libraries?
From this post https://breezejs.uservoice.com/forums/173093-1-breezejs-feature-suggestions/suggestions/7563522-which-libraries-for-java-on-github it would seem that the Json-UriBuilder branch should be used but it appears to be incompatible with the query parameters generated by the client side.
An example is the "where" clause generated by the client side is "$filter=propertyname eg value" but on the server side the EntityQuery is never looking for a "filter" parameter and even if it were it would not build a valid query because this is not valid JSON.
What is the recommended combbination of libraries and/or approach to solving the above issue?
There are two different URI formats that the Breeze client can use to send queries to the server: OData and JSON. OData is the default, so if you don't configure Breeze otherwise, that's what you will get. The recent Java server code only understands the JSON format, so you need to configure your Breeze client to send JSON. Do this before you create your entityManager:
breeze.core.config.initializeAdapterInstance("uriBuilder", "json");
Then you'll get the JSON format and have full query support.
I recently installed jclouds to use with eclipse to create a project in java to communicate with openstack. Does anyone know if there is a way to create an instance from a snapshot or using default parameters (ovf image ). I would appreciate it. Thank you very much.
Try OpenStack4j. Jcloud is only a high level basic API for OpenStack since it supports many other clouds. Example using OpenStack4j
// Create a Server Model Object
Server server = Builders.server()
.name("Ubuntu 2")
.flavor("flavorId")
.image("imageId")
.addPersonality("/etc/motd", "Welcome to the new VM! Restricted access only")
.build();
// Boot the Server
Server server = os.compute().servers().boot(server);