I am observing that the format or value of an item from a rest-assured response is changed when I try to retrieve the item using JsonPath.
Value of the field is 16637906.26 when I get the response.asString().
However when I retrieve this specific information using JsonPath, it returns the number as 1.6637906E7.
Below is the rest-assured JsonPath I used to get the data:
List<Map<String,?>> values = JsonPath.with(actResponse).param(param,value).get("entries.findAll { entries -> entries."+param+" == "+param+" }")
where param is a variable pointing to parameter I use.When I print this List, I can see that the value is then displayed as 1.6637906E7. All other smaller values are returned properly.
I tried to play with it a bit like converting the number etc, however nothing seem to work.
Highly appreciate if someone can guide me through this.
Related
I have a requirement where I need to sort based on two fields where one field is of date type and it will always have a value while sorting and the other field might be null or can contain a date value. I need to sort records in descending order based on first field and the second field should be null. I am looking for a solution in Java Elasticsearch API
SearchRequest('test').source(SearchSourceBuilder()
.query(QueryBuilders
.boolQuery()
.must(QueryBuilders.boolQuery().should(QueryBuilders.termQuery("name.keyword","george"))).sort(SortBuilders.fieldSort("createdOn").order(SortOrder.DESC)).sort(SortBuilders.scriptSort(Script("doc['updatedOn'].value == null", ScriptSortType.String)))
This solution worked in my test code (Elasticsearch-7.6.1):
.sort(SortBuilders.scriptSort(new Script(ScriptType.INLINE, "expression", "doc['updatedOn'].empty ? 0 : 1", Collections.emptyMap(), Collections.emptyMap()), ScriptSortBuilder.ScriptSortType.NUMBER).order(SortOrder.DESC))
I am stuck on this part which requires me to post multiple values to the server. I am using Retrofit.
The whole scenario is like this: there is a form where user can fill in the details like his name, age, address and can even select multiple values from certain questions. Particularly, there are 5 types of questions: Int, String, Single Choice, Boolean and Multiple Choice. As you can see I can have Int, String, Boolean and Array types.
So I created FieldMap as > to save all values in it and then posting it. I am able to post all values except Array which my server is expecting as query dict i.e. if I have FieldMap as "143": ["hello", "hey", "hi"]; server is expecting me to send it as 143=hello&143=hey&143=hi.
It is expecting me to send all array values to same key as shown above.
Can somebody help me with this? How can I achieve this using Retrofit 2?
Have you tried sth like following?
#GET("endpoint")
fun getSomething(#Query("143") items: List<String>): Call<Response>
I have a JSON string that looks like:
"{\"info\":{\"length\":{\"value\":18},\"name\":{\"value\":\"ABC\"}}}"
say, length and name are attribute names
I have another map (say attributeMap) that (created from the results I retrieve from the database) map has attribute name and attribute value association stored.
I need to be able to parse the string and compare the value an attribute has in the above string with the value returned from the attributeMap. Based on those comparisons, I will need to take some decisions.
In order to do this, I should convert the above string to a format that would help make the above comparison easier and efficient. I don't think I should be writing my own parser to do this. what would a right way to do this?
You should use any JSON Parser, like GSON (Google) (Recommended for simplicity), JACKSON, the simple org.json, or any other..
Then you will get a JSONObject/JSONNode to navigate and do the comparison.
You can find a parsing example here: How to parse JSON in Java
I want to use a pseudo field to return the distance from the center of my solr (geo) spatial search, like it's explained here: http://wiki.apache.org/solr/SpatialSearch#geodist_-_The_distance_function when it says:
Returning the distance
Solr4.0
You can use the pseudo-field feature to return the distance along with the stored fields of each document by adding fl=geodist() to the request. Use an alias like fl=dist:geodist() to make the distance come back in the dist pseudo-field instead. Here is an example of sorting by distance ascending and returning the distance for each document in dist.
...&q=:&sfield=store&pt=45.15,-93.85&sort=geodist() asc&fl=dist:geodist()
Now, I'm using solrj (4.5.1) and I can't find a way to set the fl=_dist_:geodist() part properly. I can actually manage to add it to the solrQuery object doing:
solrQuery.setParam('fl', '_dist_:geodist()')
with no compilation errors, but for some reason this is messing up my returned documents.
Any ideas how it should be done?
Ps. code is in groovy language, don't freak out for no semi-colons or string within single quotes :)
* UPDATE *
Setting the fl param as explained above, actually results in returning documents which only contains the _dist_ field!
After a few minutes of search, i found this article: http://solr.pl/en/2011/11/22/solr-4-0-new-fl-parameter-functionalities-first-look/
It explains how to return the new alias field(s) in addition to all other parameters, simply like this (please note the * part):
fl=*,stock:sum(stockMain,stockShop)
So, in my example for solrj, it will be:
solrQuery.setParam('fl', '*,_dist_:geodist()')
I have am trying to deseriliaze a JSON element where the element can contain 0 to many name/value pairs and 0 to many name/[] pairs. The values can be int, String, date, etc
An example element:
{"custom_fields":{
"custom_label_36562": 25057,
"custom_label_36677": "some string",
"custom_label_36566": [25085],
"custom_label_36564": [25076,25077,28709,25078] }}
What is the best approach to this? I tried parsing it into:
HashMap<String,List<<String>>
HashMap<String,List>`
but both times it just ends up null. I actually know the datatypes of each "custom label" so I just need to get the value into Java, and I can cast it later.
PS How do I enter a < sign without a space after it and not have all the text disappear?
Sooo no one answered this, I'm guessing I'll just desrialize it Object and take it from there...