Taken from javadoc of GSON.setPrettyPrinting :
"Configures Gson to output Json that fits in a page for pretty printing."
Ok, fitting to a page is nice. But I want it to be human readable.
and instead:
{"key":"smartphones","solutions":[{"id":"0 ","name":"LG Nexus"}]}
have:
{
"key" : "smartphones",
"solutions" : [{
"id" : "0 ",
"name" : "LG Nexus 5"
}]
}
--UPDATE --
PrettyPrinting works as expected for latest version (2.2.4).
Unfortunately, the code I used to test the question was of version 1.4, which I have to use :(
Related
I have a SpringBoot, JAX-RS, and Maven app. I'm using Swagger annotations to provide info on the REST service interface. It basically works, but I'm having trouble with some parameters that I expect a limited set of values. I believe I'm specifying the "#Api..." annotations correctly, and I can see the expected results in the swagger.json file, but the swagger-ui doesn't appear to do anything with that information.
My pom.xml appears to specify version 1.5.20 of the swagger artifacts.
The following is a heavily elided excerpt from the Java interface:
#GET
#Path("...")
#ApiOperation("...")
#ApiImplicitParams({
...
#ApiImplicitParam(name = "poi_types", value = "Types of locations to include",
allowableValues = "pos, wifi, country",
dataType = "string", paramType = "query"),
...
})
public Object ...(#QueryParam(...)
#ApiParam(name = ..., value = "...")
String ...) {
In the swagger.json, I see the following for that entry:
{
"name" : "poi_types",
"in" : "query",
"description" : "Types of locations to include",
"required" : false,
"type" : "string",
"enum" : [ "pos", "wifi", "country" ]
}
In the generated UI, I see the following:
I've seen somewhere some mentions of possible disconnects between the required schema and what swagger-ui renders, like perhaps requiring a "schema" element in the parameter definition that includes the "type"and "enum" properties. I tried manually changing the swagger.json to include that, but it made no difference.
Can anyone provide any background here?
Update:
I upgraded to swagger-core and swagger-annotations v1.6.2. I also tried putting "allowableValues" into an "#ApiParam" instead of just an "#ApiImplicitParam". Neither of these changes made any difference. I don't see any indication in the UI of the allowable values.
This is the changed element from the #ApiParam change:
{
"name" : "isocc2",
"in" : "query",
"description" : "Country code",
"required" : false,
"type" : "string",
"enum" : [ "en", "es" ]
}
This is how this displays in the swagger UI:
I also verified from the browser the swagger.json that it loaded, and it matches what I expected.
Just in case, I tested it in Chrome in addition to Firefox.
What else could be wrong here?
Have you tried using ?
public Object ...(#QueryParam(...)
#ApiParam(name = ..., value = "...",
allowableValues = "pos, wifi, country",)
String poi_types) {
allowableValues property works well on #ApiParam.
I have managed to build a working autocomplete service using Elasticsearch with Spring Boot, but I can't assign different weights for my autocomplete sentences.
While I am building the Completion object (org.springframework.data.elasticsearch.core.completion.Completion) I am using the standard constructor and next, I am assigning the weight to the object, for example (I am using Kotlin)
val completion = Completion(arrayOf("Sentence one", "Second sentence"))
completion.weight = 10
(...)
myEntity.suggest = completion
what produces the following JSON for Elasticsearch
{
"suggest" : {
"input": [ "Sentence one", "Second sentence" ],
"weight" : 10
}
}
But, according to the Elasticsearch documentation (https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html) I would like to achieve something like this
{
"suggest" : [
{
"input": "Sentence one",
"weight" : 10
},
{
"input": "Second sentence",
"weight" : 5
}
]
}
Is it possible with spring-data-elasticsearch? If yes, how can I do this?
No, at the moment the second case is currently not supported by Spring Data Elasticsearch.
Both JSON you show are valid, the first one is for multiple inputs that all have the same weight, the second one is for multiple inputs, when ich input has a different weight.
Please file an issue in Spring Data Elasticsearch Jira to add support for the Completion object to support this case.
Say I have documents stored like below.
document 1
{
id : '1',
title : "This is a test document1",
list : ["value1" , "value2"],
...
}
document 2
{
id : '2',
title : "This is a test document2",
valueList : ["value1" , "value2"],
...
}
I need to add some more elements to the valueList in the documents with a list of document ids using bulk api. The resulting should look like
document 1
{
id : '1',
title : "This is a test document1",
list : ["value1" , "value2", "value3"],
...
}
document 2
{
id : '2',
title : "This is a test document2",
valueList : ["value1" , "value2" , "value3"],
...
}
What can I do to achieve this?
I tried using the scripts but it only updates a single document.
Sorry am really new to elastic search. I could even be stupid on this question. Please forgive and make me clear with this question.
See Updating Document. It should be straightforward. You need to use _update and just to give you an idea, even though the documentation is nearly perfect, it could look like this:
POST /your_index/your_type/document1/_update
{
id : '1',
title : "This is a test document1",
list : ["value1" , "value2", "value3"]
}
This will update document1.
In case of bulk updates you should read Batch Processing and have a look at the Bulk API.
From the docs:
POST /your_index/your_type/_bulk
{ "update" : {"_id" : "document1", "_type" : "your_type", "_index" : "your_index"}}
{ "doc" : {"myfield" : "newvalue"} }
{ "update" : {"_id" : "document2", "_type" : "your_type", "_index" : "your_index"}}
{ "doc" : {"myfield" : "newvalue"} }
Please note that you can just use _update for Partial Updates.
The simplest form of the update request accepts a partial document as
the doc parameter, which just gets merged with the existing document.
Objects are merged together, existing scalar fields are overwritten,
and new fields are added.
Sup, good folks of the internet.
Does anyone know how to make nested queries for mongodb? This is probably best explained by an example. To retrieve specific fields, I can use the :fields option to retrieve that field (e.g. suppose it is called "useful_field"):
collection.find({},{:fields => {"useful_field" => 1}})
But suppose that useful_field itself contains an array of many further fields, i.e
useful_field = [{"value_I_want"=>"useful","value_I_dont_want"=>"not_useful"}]
My aim is to select "value_I_want". Any thoughts?
Here is a specific entry that I am trying to deal with (a reply to a tweet):
{ "_id" : ObjectId("51b6f71b0364718d71e4bca5"),
"annotations" : { },
"resultType" : "Tweet",
"score" : 1,
"groupName" : "TweetsWithConversation",
"results" : [
{
"kind" : "Tweet",
"score" : 1,
"annotations" : { "ConversationRole" : "Ancestor" },
"value" : { "created_at" : "Fri Jun 07 19:47:51 +0000 2013",
"id" : NumberLong("343091955196104704"),
"id_str" : "343091955196104704",
"text" : "THIS_IS_WHAT_I_WANT",
etc. etc. (Apologies for the odd formatting)
I'm trying to use a method of the form that will let me do something like this:
db.collection.find({},{:fields { some_way_of_selecting(THIS_IS_WHAT_I_WANT)})
(I'm querying as part of a ruby script)
Otherwise, I'll have to go back into the dark world of regex. No-one wants that.
Try the following
db.collection.find({},{"useful_field.value_I_want": 1})
Maybe try this:
db.collection.find({"resultType" : "Tweet"}, {"results" : {$elemMatch : {"value.text" : "THIS_IS_WHAT_I_WANT"}}})
What you are trying to do is called "projection" - it's specifying what fields you want returned in the second argument to find.
In your case you simply want:
db.collection.find({}, {"results.value.text":1} )
When doing a search, Elasticsearch returns a data structure that contains various meta information.
The actual result set is contained within a "hits" field within the JSON result returned from the database.
Is it possible for Elasticsearch to return only the needed data (the contents of then "hits" field) without being embedded within all the other meta data?
I know I could parse the result into JSON and extract it, but I don't want the complexity, hassle, performance hit.
thanks!
Here is an example of the data structure that Elasticsearch returns.
{
"_shards":{
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits":{
"total" : 1,
"hits" : [
{
"_index" : "twitter",
"_type" : "tweet",
"_id" : "1",
"_source" : {
"user" : "kimchy",
"postDate" : "2009-11-15T14:12:12",
"message" : "trying out Elastic Search"
}
}
]
}
}
You can at least filter the results, even if you cannot extract them. The "common options" page of the REST API explains the "filter_path" option. This lets you filter only the portions of the tree you are interested in. The tree structure is still the same, but without the extra metadata.
I generally add the query option:
&filter_path=hits.hits.*,aggregations.*
The documentation doesn't say anything about this making your query any faster (I doubt that it does), but at least you could return only the interesting parts.
Corrected to show only hits.hits.*, since the top level "hits" has metadata as well.
No, it's not possible at this moment. If performance and complexity of parsing are the main concerns, you might want to consider using different clients: java client or Thrift plugin, for example.