I am trying out API Blueprint and found some things, which are not quite clear to me.
1. How can I document POST body parameters?
There is + Parameters but it just documents query parameters. If I now want to describe a POST API I can't document POST parameters (application/x-www-form-urlencoded). The same goes for JSON (see #3).
2. Is there a way to add a description to a response?
I tried
+ Response 403
If the request request is made with HTTP instead of HTTPS.
But this just adds the text as the body response.
3. Describe the different fields of my response
If I return JSON I want to describe each field separately, its type and its purpose. Is there a way to do that?
Thanks!
Lets look #1 and #3 together as they are closely related:
Description of payload fields
Currently there is no dedicated syntax for discussing the actual fields of a payload (model, response or request).
For now it is up to you how do you describe it using any Markdown syntax you like.
The plan is to provide a Markdown syntax for discussing these fields / parameters like this:
JSON:
{
"id": 1,
"name": "A green door",
"price": 12.50,
"tags": ["home", "green"]
}
and its description in blueprint:
- id: 1 (integer) - The unique identifier for a product
- name: A green door (string) - Name of the product
- price: 12.50 (number)
- tags: home, green (optional, array of strings)
I am currently working on this. More details can be found here.
Response description
You can already add any markdown formatted discussion to a payloads
# Resource [/r]
## List [GET]
+ Response 200
This response will list the R
+ Body
{ ... }
More info here: https://stackoverflow.com/a/19433269/634940
Note: In order for the description to appear correctly in Apiary you might need to use the New Apiary Rendered documentation
Related
i have mapped around 20 fields from the sample data. All of them come under Observation category. I have a field/Label which we created to denote each patient.
"PatientLabel" : 0
I understand FHIR is all about fixed set of items. But, is there a way to include this in FHIR Json. i would need this information while processing.
"extension": [
{
"name": "PatientLabel",
"value": 0
}
tried the above one.. FHIR validator is throwing error
Extensions don't have a 'name', they have a 'url'. Also, 'value' is a polymorphic type, so you'd need "valueInteger" or "valueDecimal". That said, "0" seems an unusual value for something titled "patient label". Normally, the Patient would be in the Observation.subject. If you just have a label and not a reference, you could use subject.display and not need an extension at all...
The following is my query:
https://maps.googleapis.com/maps/api/geocode/json?latlng=53.477752,-2.266695&result_type=street_address&key=*****
and it returns empty result:
{
"plus_code": {
"compound_code": "FPHM+48 Salford, UK",
"global_code": "9C5VFPHM+48"
},
"results": [],
"status": "ZERO_RESULTS"
}
I have tested the coordinates 53.477752,-2.266695 on https://www.latlong.net with the place name "Manchester" and the website is showing King Street which is correct. Why GoogleAPI returns ZERO_RESULTS? Is this issue a still bug in Google or do I need to add additional parameters?
Upon testing the coordinate (53.477752,-2.266695), I was able to get a couple of results. However, it seems that not one of the address results contains the result_type "street_address". This is the reason why you get zero results as a response, since you've added a result_type=street_address filter in the query.
Please see the Geocoder tool to see the actual results. Here's the sample request: https://maps.googleapis.com/maps/api/geocode/json?&latlng=53.477752,-2.266695&key=YOUR_API_KEY
Using elasticsearch JS client,if I want to get all the indices, it provides an API https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-cat-indices
However, the output format is string.
If I want to find the latest index, I need to manipulate the string such as split by space, iterate thru the array and filter the content by some criteria etc..
Instead, Is it possible to get json output from the API?
PS: I did notice this thread which is suggesting to use /*/_aliases and that works well but I was wondering how to leverage elasticsearch js client APIs
The cat APIs are meant to be consumed by humans (hence not JSON).
If you want to get JSON data, you can use the indices.stats call (which hits the /_stats API endpoint).
client.indices.stats({
index: "_all",
level: "indices"
}, function(err, res) {
// res contains JSON data about indices stats
});
UPDATE:
Actually, the cat APIs also return JSON data, if you specify the parameter format: json in the request:
client.cat.indices({"format": "json"}, function(err, res) {
...
});
I recently inherited an ES instance and ensured I read an entire book on ES cover-to-cover before posting this, however I'm afraid I'm unable to get even simple examples to work.
I have an index on our staging environment which exhibits behavior where every document is returned no matter what - I have a similar index on our QA environment which works like I would expect it to. For example I am running the following query against http://staging:9200/people_alias/_search?explain:
{ "query" :
{ "filtered" :
{ "query" : { "match_all" : {} },
"filter" : { "term" : { "_id" : "34414405382" } } } } }
What I noticed on this staging environment is the score of every document is 1 and it is returning EVERY document in my index no matter what value I specify ...using ?explain I see the following:
_explanation: {
value: 1
description: ConstantScore(*:*), product of:
details: [
{
value: 1, description: boost
}, { value: 1, description: queryNorm } ] }
On my QA environment, which correctly returns only one record I observe for ?explain:
_explanation: {
value: 1
description: ConstantScore(cache(_uid:person#34414405382)), product of:
details: [ {
value: 1,
description: boost
}, {
value: 1,
description: queryNorm
}
]
}
The mappings are almost identical on both indices - the only difference is I removed the manual field-level boost values on some fields as I read field-level boosting is not recommended in favor of query-time boosting, however this should not affect the behavior of filtering on the document ID (right?)
Is there any clue I can glean from the differences in the explain output or should I post the index mappings? Are there any server-level settings I should consider checking? It doesn't matter what query I use on Staging, I can use match queries and exact match lookups on other fields and Staging just keeps returning every result with Score 1.0
I feel like I'm doing something very glaringly and obviously wrong on my Staging environment. Could someone please explain the presence of ConstantScore, boost and queryNorm? I thought from looking at examples in other literature I would see things like term frequency etc.
EDIT: I am issuing the query from Elastic Search Head plugin
In your HEAD plugin, you need to use POST in order to send the query in the payload, otherwise the _search endpoint is hit without any constraints.
In your browser, if you open the developer tools and look at the networking tab, you'll see that nothing is sent in the payload when using GET.
It's a common mistake people often do. Some HTTP clients (like curl) do send a payload using GET, but others (like /head/) don't. Sense will warn you if you use GET instead of POST when sending a payload and will automatically force POST instead of GET.
So to sum it up, it's best to always use POST whenever you wish to send some payload to your servers, so you don't have to care about the behavior of the HTTP client you're using.
I'm trying to write a query that finds articles based on their comments.
So if a user is trying to find "chocolates"
{
type: "article",
id: "myArticle1",
title: "something about brown food"
}
{
body: "I love chocolates!",
type:"comment",
commentOf: "myArticle1"
}
In this example I have both documents in the same index and I'm trying to get the "myArticle1" document via the comment matching chocolates in body. How do I do this? Is it with the top_children query?
You can use the parent-child in ES to achieve this:
Define the parent (article) and child (comment)
Index data. You should know how to index child data as it will difference from normal (need to specify parent in the index request)
Use has_child query to query for article that matched some
fields in comment
I wrote a full working sample script for it: https://gist.github.com/dqduc/efa66047358dac66461b
You can run it to test and send me your feedback. I guess you're new to ES and parent-child relationship in ES.