Insert into elasticsearch with an id that contains slashes - spring

Hello I am trying to insert an object into elasticsearch using it's API, the problem is that the IDs of elements that I want to insert are like this : ee5z4d5/54zd15zd/5zd45
when I sent a post request to host/index/id with a body, I got an error because the request url is host/index/ee5z4d5/54zd15zd/5zd45
I am using spring boot with feign client to comminucate with elasticsearch, and my question is how I can solve this problem

You need to URL-encode your ID first, i.e. the URL must look like this
host/index/ee5z4d5%2F54zd15zd%2F5zd45
I don't know Feign but this issue might provide some insights on how to solve your issue.

Tldr;
This is not an Elastic issue but more a web issue.
What you need to do, is encode the special char in the url.
Look at the solution below to find out what it means.
Solution
POST /73690410/_doc/ee5z4d5%2F54zd15zd%2F5zd45
{
"data": "my id has some slash"
}

Related

I want to consume a GraphQL web API in .NET

I want to consume data from a GraphQL API.
how can I achieve that? I am new to webapi and any help is appreciated
Assuming the API you want to consume uses HTTP, you should be able to use cUrl, wget, Charles, Postman or even just the URL bar in a browser to make a request.
To write your first query, you can start with the following:
query theNameOfMyQuery {
}
Now that you have a named query, you can start populating it with whatever fields your GraphQL server is exposing. For a blog example, you might have something like this:
query theNameOfMyQuery {
posts {
title
author
}
}
Now, to turn that into something you can request, all you need to do is URL encode it and add it to your URL. A typical URL looks like this:
https://www.someserver.com/?query=...&variables=...
So for the above example, you would have the above query
https://www.someserver.com/?query=query%20theNameOfMyQuery%20%7B%0D%0A%20%20posts%20%7B%0D%0A%20%20%20%20title%0D%0A%20%20%20%20author%0D%0A%20%20%7D%0D%0A%7D
Some Resources:
Evolution of API Design - this video explains some of the concepts of GraphQL and why it exists.
howtographql.com - This is an amazing set of tutorials for every implementation you could imagine

Spring JPA With mongo Supporting Contains and LessThan

I am using Spring JPA with mongo.I have a requirement to use contains query on one of the fields.If end users(UI/Service) hits the GET Request and looks for information in EMAIL Field,I need to search based on text.Pretty much it is like.
https://docs.spring.io/spring-data/jpa/docs/current/reference/html/
This link explains that We can Use Contains to get the Data.
List<ScheduledNotification> findByMobileNumberContaining(String mobileNumber);
List<ScheduledNotification> findByEmailIdIgnoreCaseContaining(String emailId);
But when I am using this API,I am not able to get the data.So ,has any one done something like using Contains.
well ,I was not sending content type in header attribute in GET request.So yes it works,alright.There was no issue with method signature.

JMeter: SPARQL Query HTTP Request not updating DB

I have recently started working with SPARQL and JMeter. I was trying to load test Stardog. For that I used Jmeter and ran a SPARQL query which updates a value in the database, using HTTP Request. I tried running the Query in Stardog web interface and it changes the value in the DB just fine. When I run the same query using Jmeter it runs just fine but does not change the values in the DB. It would be very helpful if I knew what I am doing wrong. The query I am running is:
PREFIX info: <http://somewhere/peopleInfo#>
PREFIX vcard:<http://www.w3.org/2001/vcard-rdf/3.0#>
DELETE { ?person info:age ?age }
INSERT { ?person info:age ?nage }
WHERE {
?person vcard:FN 'Becky Smith' .
?person info:age ?age
BIND (?age+1 AS ?nage)
}
The screenshots of Jmeter can be found here:
https://onedrive.live.com/redir?resid=E29D7716CE8E7022!239767&authkey=!AEzPJtZJi-bbmjw&ithint=folder%2cpng
The rdf file I am using in Stardog can be found here (https://onedrive.live.com/redir?resid=E29D7716CE8E7022!239766&authkey=!ALBbaxM8nHhAXSw&ithint=file%2crdf).
Any help will be greatly appreciated. Thank you.
[Sorry for uploading Onedrive links, I am a new user and do not have enough reputation points to upload more than 2 links.]
I've not used JMeter, so I don't have any definitive answer on what precisely is wrong with your configuration, but I can see that there is some issue with it.
The expected format for submitting a POST to Stardog's query endpoint is that the Content-Type is application/x-www-form-urlencoded and the body should be the query parameters sent to the endpoint. So, like with a GET request, it's expecting that to be query=<your query>. Looking at the second screenshot, it doesn't like that's configured correctly.
This is confirmed by the response type of text/turtle and the response content of Stardog's SPARQL service description, which is what Stardog sends when the request is missing the query parameter.
I realized the mistake I was making. I was using HTTP Body to paste my SPARQL code. Instead when I used Parameters and added the SPARQL code under Query. It should look like the picture.
Parameter

How to do Partial Response with Google URL Shortener API

Looking at the documentation on this API there is a page on performance to cut back the number of keys in the JSON dictionary returned. URL Shortener Performance Tips
Of the three dictionary keys returned in the insert request of this API, I am only interested in the shortened URL. The id key. Looking at the above documentation I would have expected this to work:
The POST request https://www.googleapis.com/urlshortener/v1/url?fields=id?key=YOUR-API-KEY
But with the fields=id added the request comes back invalid.
How do you set only a partial response for this API to only return the id key?
Turns out the comment from abraham steered me in the right direction on this problem. I was able to find the Try it tool option without OAuth and it worked also to my surprise. Looking at the request it generated I found that it was a syntax error on my part looking at the url given in my original question. It should be:
?fields=id&
not
?fields=id?

rest url - having '/' as a path VALUE

I think this is not possible, but I need confirmation before throwing it away...
I have a GET REST endpoint with this pattern
/networks/{networkId}/publishers/{publisherId}/ratings
the problem I am facing is, publisherId could have '/' in its id, like the id could be "opt/foo/bar" (we have not control over this id, it is given to us by our clients).
So
/networks/68/publishers/opt/foo/bar/ratings - obviously does not work, getting a url not fond error.
/networks/68/publishers/opt%2ffoo%2fbar/ratings - also does not work. same error.
I know passing it as a query param will work. But I want to know if there is a way to make it work having it as a path param?
Thanks!
URL encoding is the right way to go but it looks like your container is decoding the slash before Jersey receives it.
Assuming you are using Tomcat, you can attempt to persuade Tomcat to allow the encoding, try:
tomcat/bin/setenv.bat
set
CATALINA_OPTS="-Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true"
I don't know if other containers have similar issues and settings.
I have not tried this, but theoretically this should work in Jersey:
#Path("/networks/{networkId}/publishers/")
#GET
public String get(#PathParam("networkId") String networkId, #Context UriInfo ui) {
java.util.List<PathSegment> segments = ui.getPathSegments();
// Last segment is "ratings", the rest is your publisherId.
}

Resources