ElasticSearch: Indexing with multiple mapping types - post

I am trying to fully comprehend indexing with multiple mapping types in ElasticSearch. In the docs it gives example code:
PUT my_index
{
"mappings": {
"user": {
"_all": { "enabled": false },
"properties": {
"title": { "type": "string" },
"name": { "type": "string" },
"age": { "type": "integer" }
}
},
"blogpost": {
"properties": {
"title": { "type": "string" },
"body": { "type": "string" },
"user_id": {
"type": "string",
"index": "not_analyzed"
},
"created": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
}
}
}
}
}
With this mapping how would I then create and search on an object?
For create would it be:
POST my_index/user/blogspot
or
POST my_index/user,blogspot
For searching would it be:
GET my_index/user/blogspot
or
GET my_index/user,blogspot
or something else?
An example of a POST and GET with multiple mapping would really help me out. Thank you so much!

Related

LogicApps / Graph API - delete an email from a shared mailbox

as per title.
Whilst dealing with my own mailbox is fine I wish to ideally process a shared mailbox in LogicApps. I can read the emails but I want to clean-up by deleting the messages.
Logic Apps doesn't seem to offer that action and unless mistaken the graph api doesnt either?
Has anyone managed this?
This has been possible since the update on 6th May 2020. A number of the actions now support an Original Mailbox Address optional parameter that you can set to access the shared mailbox:
As of May 6, 2020, shared mailbox support was added for certain operations with an optional 'Mailbox address' parameter, allowing you to specify a shared mailbox address for your operation to access.
The Delete Email (V2) action supports this parameter:
You then fill in the email address of your shared mailbox:
Which will then successfully find your message id and delete the email for you:
For this requirement, I write a logic app sample for your reference:
Before we start, provide the whole logic app:
1. In first "HTTP" action, I request for the access token.
2. Then I add a "Parse JSON" action to parse the response from the first "HTTP" action to get the access token.
The schema should be:
{
"properties": {
"access_token": {
"type": "string"
},
"expires_in": {
"type": "integer"
},
"ext_expires_in": {
"type": "integer"
},
"token_type": {
"type": "string"
}
},
"type": "object"
}
3. In the second "HTTP" action, I request for all of the messages by the access token from above steps.
4. After that, we need to use another "Parse JSON" action to parse the response from "HTTP 2".
The schema should be:
{
"properties": {
"##odata.context": {
"type": "string"
},
"value": {
"items": {
"properties": {
"##odata.etag": {
"type": "string"
},
"bccRecipients": {
"type": "array"
},
"body": {
"properties": {
"content": {
"type": "string"
},
"contentType": {
"type": "string"
}
},
"type": "object"
},
"bodyPreview": {
"type": "string"
},
"categories": {
"type": "array"
},
"ccRecipients": {
"type": "array"
},
"changeKey": {
"type": "string"
},
"conversationId": {
"type": "string"
},
"conversationIndex": {
"type": "string"
},
"createdDateTime": {
"type": "string"
},
"flag": {
"properties": {
"flagStatus": {
"type": "string"
}
},
"type": "object"
},
"from": {
"properties": {
"emailAddress": {
"properties": {
"address": {
"type": "string"
},
"name": {
"type": "string"
}
},
"type": "object"
}
},
"type": "object"
},
"hasAttachments": {
"type": "boolean"
},
"id": {
"type": "string"
},
"importance": {
"type": "string"
},
"inferenceClassification": {
"type": "string"
},
"internetMessageId": {
"type": "string"
},
"isDeliveryReceiptRequested": {
"type": "boolean"
},
"isDraft": {
"type": "boolean"
},
"isRead": {
"type": "boolean"
},
"isReadReceiptRequested": {
"type": "boolean"
},
"lastModifiedDateTime": {
"type": "string"
},
"parentFolderId": {
"type": "string"
},
"receivedDateTime": {
"type": "string"
},
"replyTo": {
"type": "array"
},
"sender": {
"properties": {
"emailAddress": {
"properties": {
"address": {
"type": "string"
},
"name": {
"type": "string"
}
},
"type": "object"
}
},
"type": "object"
},
"sentDateTime": {
"type": "string"
},
"subject": {
"type": "string"
},
"toRecipients": {
"items": {
"properties": {
"emailAddress": {
"properties": {
"address": {
"type": "string"
},
"name": {
"type": "string"
}
},
"type": "object"
}
},
"required": [
"emailAddress"
],
"type": "object"
},
"type": "array"
},
"webLink": {
"type": "string"
}
},
"required": [
"##odata.etag",
"id",
"createdDateTime",
"lastModifiedDateTime",
"changeKey",
"categories",
"receivedDateTime",
"sentDateTime",
"hasAttachments",
"internetMessageId",
"subject",
"bodyPreview",
"importance",
"parentFolderId",
"conversationId",
"conversationIndex",
"isDeliveryReceiptRequested",
"isReadReceiptRequested",
"isRead",
"isDraft",
"webLink",
"inferenceClassification",
"body",
"sender",
"from",
"toRecipients",
"ccRecipients",
"bccRecipients",
"replyTo",
"flag"
],
"type": "object"
},
"type": "array"
}
},
"type": "object"
}
5. Then use a "For each" and loop the value from "Parse JSON 2".
6. In "For each", we need to add third "HTTP" action as below screenshot:
7. Run the logic app, it will delete all of the messages in shared mailbox.
By the way:
Before run the logic app, you need to search the client_id in your azure ad app registrations to find the application and add the Mail.ReadWrite permission to it. Also don't forget grant admin consent for it.

Swagger 3.0 reDoc Discriminator JSON

I'm currently writing swagger 3.0 documentation and using reDoc to render as nice UI for it. I have a few scenarios in my documentation where based on a previous properties enum I would want to display different schema object properties. Sadly I cant seam to figure out how to wire this together properly in my documentation. So far I have the following test endpoint:
{
"post": {
"operationId" : "test",
"summary": "test",
"description": "test",
"tags": [ "test" ],
"consumes": "application/json",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"oneOf": [
{
"$ref": "./schemas/test1.json"
},
{
"$ref": "./schemas/test2.json"
}
],
"discriminator": {
"propertyName": "pet_type",
"mapping": {
"click": "./schemas/test1.json",
"open": "./schemas/test2.json"
}
}
}
}
}
},
"responses": {
"200": {
"description": "Success"
}
}
}
}
The test1.json looks like this:
{
"Cat": {
"type": "object",
"properties": {
"pet_type": {
"type": "string"
},
"hunts": {
"type": "boolean"
},
"age": {
"type": "integer"
}
},
"discriminator": {
"propertyName": "pet_type"
}
}
}
And the test2.json like this:
{
"Dog": {
"type": "object",
"properties": {
"pet_type": {
"type": "string"
},
"bark": {
"type": "boolean"
},
"breed": {
"type": "string",
"enum": [
"Dingo",
"Husky",
"Retriever",
"Shepherd"
]
}
},
"discriminator": {
"propertyName": "pet_type"
}
}
}
The desired out come would be to toggle between the two "test" jsons based on an enum (the drop down seen in the reDoc sample). What am I missing to get this result?
You can see an example of the discriminator result here under the feature section (the first gif)
After more digging I was able to figure out the issue... my structure for the most part.
On my index.json file I updated my components section to point at my components folder containing the schema as such:
"components": {
"$ref": "./components/test.json"
},
The test.json looks like the following:
{
"schemas": {
"Refinance": {
"description": "A representation of a cat",
"allOf": [
{
"$ref": "#/schemas/Pet"
},
{
"type": "object",
"properties": {
"huntingSkill": {
"type": "string",
"description": "The measured skill for hunting",
"default": "lazy",
"enum": [
"clueless",
"lazy",
"adventurous",
"aggressive"
]
}
},
"required": [
"huntingSkill"
]
}
]
},
"Purchase": {
"description": "A representation of a dog",
"allOf": [
{
"$ref": "#/schemas/Pet"
},
{
"type": "object",
"properties": {
"packSize": {
"type": "integer",
"format": "int32",
"description": "The size of the pack the dog is from",
"default": 1,
"minimum": 1
},
"foobar": {
"type": "string",
"description": "some ol bullshit"
}
},
"required": [
"packSize"
]
}
]
},
"Pet": {
"type": "object",
"discriminator": {
"propertyName": "petType"
},
"properties": {
"petType": {
"description": "Type of a pet",
"type": "string"
}
},
"xml": {
"name": "Pet"
}
}
}
}
And finally the schema for the endpoint gets referenced as follows:
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "../../index.json#/components/schemas/Pet"
}
}
}
},

Can we refer to a only one property of other schema

I have a rest service, that can work as below:
http://server/path/AddressResource and
http://server/path/AddressResource/someAnotherPath
I have a definitions like below.
"definitions": {
"address": {
"type": "object",
"properties": {
"street_address": { "type": "string" },
"city": { "type": "string" },
"state": { "type": "string" }
},
"required": ["street_address", "city", "state"]
}
}
that is the response of path1, and in path two i just want to return the "city" property of address.
Can I create a schema, referring to address and using just one of it's property?

Object array rendered as empty array in Swagger UI

I have the following model definitions in an OpenAPI/Swagger spec:
"definitions": {
"models.Equipment": {
"title": "Equipment",
"type": "object",
"properties": {
"Features": {
"type": "array",
"items": {
"$ref": "#/definitions/models.Feature"
}
},
"Id": {
"type": "integer",
"format": "int64"
},
"IdType": {
"type": "string"
},
"Name": {
"type": "string"
},
"Price": {
"type": "integer",
"format": "int32"
}
}
},
"models.Feature": {
"title": "Feature",
"type": "object",
"properties": {
"Equipments": {
"type": "array",
"items": {
"$ref": "#/definitions/models.Equipment"
}
},
"Id": {
"type": "integer",
"format": "int64"
},
"IdFeature": {
"$ref": "#/definitions/models.Feature"
},
"Name": {
"type": "string"
}
}
}
}
In the Feature model, he Equipments property is defined as an array of Equipment models, but Swagger UI 3.x renders it as an empty array []. Everywhere Feature model is used, like as examples for POST method in Feature I have this kind of display.
Is the definition incorrect in some way?
The complete spec is here:
https://dl.dropboxusercontent.com/s/anjfhgxhr0pfmnu/swagger-bug.json
This seems to be a bug in Swagger UI and is most likely caused by circular references in your models - models.Equipment references models.Feature, and models.Feature references models.Equipment. You can open an issue in the Swagger UI repository on GitHub.
Your spec also contains errors in the response definitions:
"responses": {
"200": {
"schema": {
"$ref": "#/definitions/models.Equipment"
}
},
"403": {}
}
Each response must have a description, so the correct version would be:
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.Equipment"
}
},
"403": {
"description": "Oops"
}
}

restAssured json schema validation - reading json schema file assertion getting failed

I am using restAssured for my json schema validation.
Below is my script for assertion:
String JsonString = response.asString();
Assert.assertEquals(JsonString,matchesJsonSchemaInClasspath("quotesschema.json"));
And I have placed my quotesschema.json file in project/bin folder.
When I run my test script, assertion fails with below message
java.lang.AssertionError: expected [] but found [actual api response]
Also, I validated my schema against api response thru http://json-schema-validator.herokuapp.com/ schema validator.
Not sure whether its reading my schema inside the .son file.
Below is my schema.
{
"type": "object",
"$schema": "http://json-schema.org/draft-03/schema",
"title": "quotes-schema",
"description": "JSON Schema for Quotes",
"properties": {
"result": {
"type": "object",
"properties": {
"Quotes": {
"type": "array",
"properties": {
"DisplaySymbol": {
"type": "string"
},
"Identifier": {
"type": "string"
},
"Exchange": {
"type": "string"
},
"Trade": {
"type": "string"
},
"Date": {
"type": "string"
},
"Change": {
"type": "string"
},
"Bid": {
"type": "string"
},
"BidSize": {
"type": "string"
},
"Ask": {
"type": "string"
},
"AskSize": {
"type": "string"
},
"High": {
"type": "string"
},
"Low": {
"type": "string"
},
"Volume": {
"type": "string"
},
"Open": {
"type": "string"
},
"PreviousClose": {
"type": "string"
},
"High52Week": {
"type": "string"
},
"High52WeekDate": {
"type": "string"
},
"Low52Week": {
"type": "string"
},
"Low52WeekDate": {
"type": "string"
},
"PERatio": {
"type": "string"
},
"MarketCap": {
"type": "string"
},
"SharesOutstanding": {
"type": "string"
},
"RollingEPS": {
"type": "string"
},
"IsDefault": {
"type": "string"
},
"IsIndex": {
"type": "string"
},
"Class": {
"type": "string"
}
}
}
}
}
}
}
matchesJsonSchemaInClasspath method returns JsonSchemaValidator class and not a String.
That's why your Assert will not work, where strings are compared:
JsonString = response.asString();
Assert.assertEquals(JsonString,matchesJsonSchemaInClasspath("quotesschema.json"));
Actual usage be inside body() method as explained below:
get("RESTPATH").then().assertThat().body(matchesJsonSchemaInClasspath("quotesschema.json"));

Resources