query output to email action - elasticsearch

I am trying to use watcher API to send alerts.
https://www.elastic.co/guide/en/elasticsearch/reference/5.5/watcher-api-put-watch.html
I am able to set an example as explained above. When I check my mail, I can see the "subject" line correctly. But I need the output of a query as body of the email.
How is this achieved using x-pack?

In the example at the documentation, it only specifies the subject.
You can see an example with body in this page:
https://www.elastic.co/guide/en/x-pack/5.5/actions-email.html
It specifies the body, and adds the response in JSON format to the attachment of the email.
...
"actions" : {
"email_administrator" : {
"email" : {
"to" : "sys.admino#host.domain",
"subject" : "Encountered {{ctx.payload.hits.total}} errors",
"body" : "Too many error in the system, see attached data",
"attachments" : {
"attached_data" : {
"data" : {
"format" : "json"
}
}
},
"priority" : "high"
}
}
]
...

Related

document field returns null when querying groups of Prismic Content-Realtionship fields in graphql

Issue:
I am using Prismic to send data through to my website.
In Prismic I have a Type (testimonial_list) that consists of a group of content-relation fields (Prismic Type testimonials).
To query the data on the inner Types I need to access them via the document field in graphql and use inline-fragments.
I have followed as instructed here:
https://github.com/angeloashmore/gatsby-source-prismic#Query-Content-Relation-fields
Inside graphql I have managed to navigate to the testimonial data-fields (on the document field) but the document field returns null, this is where I'm stuck. I can't work out why it would return null as the content exists and the fields are clearly being found in graphql.
Info:
My project is built using Gatsby and I'm using the plugin gatsby-source-prismic v3.1.1
Here you can see I can access the correct field data and I am getting the right number of nodes returned but document is empty:
This is the JSON for the testimonial_list Type on Prismic:
{
"Main" : {
"prismic_title" : {
"type" : "StructuredText",
"config" : {
"single" : "heading6",
"label" : "Title (only used to name entry in Prismic list)",
"placeholder" : "Prismic list title (otherwise \"undefined\")"
}
},
"page" : {
"type" : "Select",
"config" : {
"options" : [ "Homepage", "Option 2", "Option 3" ],
"label" : "Website page to appear on:"
}
},
"testimonial_list" : {
"type" : "Group",
"config" : {
"fields" : {
"testimonial" : {
"type" : "Link",
"config" : {
"select" : "document",
"customtypes" : [ "testimonial" ],
"label" : "testimonial"
}
}
},
"label" : "Testimonial List"
}
}
}
}
Thank you for any help, if there is any more info I can supply to help deduce the issue please let me know.
In the end, the issue turned out to be a typo in my gatsby-config where I was requiring the schema.
It was a daft mistake but stare at something too long and these things happen I guess.
In case anybody else has a similar issue you must ensure the property names of your Prismic schemas inside your gatsby-config are exactly the same as in Prismic.
For example if your Type in Prismic is called "my_type" then you must use that exact syntax - so for example don't use "myType".
Hey it might be something related to the gatsby-source-prismic plugin
I would directly open an issue for it here if I were you: https://github.com/angeloashmore/gatsby-source-prismic/issues

Google places API - Can I separate out the output?

Hiting the endpoint:
https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=Hoboken%20NJ&fields=formatted_address,name&inputtype=textquery&key=xxxxxxxxxxxxxxxxxxx
Getting the result:
{
"candidates" : [
{
"formatted_address" : "New Jersey, USA",
"name" : "Hoboken"
}
],
"debug_log" : {
"line" : []
},
"status" : "OK"
}
What bugs me is that I can't find a way to separate out the region and country - Yes, I know I can parse the result myself. But is there an option I get shoot out to Google Places API to have the response separate out city/state(or region)/country in the returned JSON?
Something like:
{
"candidates" : [
{
"state" : "New Jersey",
"country" : "USA",
"name" : "Hoboken"
}
],
"debug_log" : {
"line" : []
},
"status" : "OK"
}
As far as I know, it isn't possible, you'll have to parse it. Places API is designed to search businesses and POIs at first place.
Google does have, however a geocoding API which seems to give out Postal Code, Country, State, Address, separetely.
There are also some free alternatives

MailChimp send the same email multiple times

Is it possible to send the same email multiple times?
I tried via API to add email to queue, but I cannot remove it anyway. And if I don't, I get message "You've already sent this email to the subscriber." There was answer in another question. However, I need to be able to send email many (not constant) times, thus creating N amount of campaigns does not work for me. Therefore, the only option was to remove subscriber from list and add it back again, however, also doing this did not trigger the email to be sent.
Am I out of luck with MailChimp, is there a way or am I doing something wrong?
You are doing rigth, it is one of mailchimp 'smart' restrictions, like 'no more than 255 symbols in merge field'. You can workaround it, just create new campaign with one email.
I post example below, replace placeholders with rigth values. You can find TEMPLATE_ID in browser address bar when you edit template. (templates/design?tid=TEMPLATE_ID)
POST https://usX.api.mailchimp.com/3.0/campaigns
{
"type" : "regular",
"recipients" : {
"list_id" : "${LIST_ID}",
"segment_text" : "${SUBJECT}",
"segment_opts" : {
"match" : "all",
"conditions" : [ {
"condition_type" : "TextMerge",
"op" : "is",
"field" : "EMAIL",
"value" : "${USER_EMAIL}"
} ]
}
},
"settings" : {
"subject_line" : "${SUBJECT}",
"title" : "${SUBJECT}",
"from_name" : "${YOUR_COMPANY}",
"reply_to" : "${YOUR_COMPANY_EMAIL}",
"to_name" : "*|FNAME|* *|LNAME|*",
"template_id" : ${TEMPLATE_ID}
}
}
after creating, check subscriber count ( should be "recipient_count":1), save campaign id and start campaign.
POST https://usX.api.mailchimp.com/3.0/campaigns/${CAMPAIGN_ID}/actions/send
after that, wait some time, no less than 1 min, and delete campaign with
DELETE https://usX.api.mailchimp.com/3.0/campaigns/${CAMPAIGN_ID}

How to create elasticsearch watcher by xpack

I just tried working with elasticsearch and now trying to create first watcher
There are some information I have read in elasticsearch documentation : https://www.elastic.co/guide/en/x-pack/current/watcher-getting-started.html
And now I trty to create one :
https://es.origin-test.cloud.rccf.ru/apiconnect508/_xpack/watcher/watch/audit_watch
PUT method + auth headers
I put in :
{ "trigger" : {
"schedule": {
"interval": "1h"
}
}, "actions" : { "send_email" : {
"email" : {
"to" : "ext_avolkova#rencredit.ru",
"subject" : "Watcher Notification",
"body" : "{{ctx.payload.hits.total}} logs found"
} } } }
But now I see mistake :
No handler found for uri
[/apiconnect508/_xpack/watcher/watch/log_audit] and method [PUT]
Please, help me to create one simple watcher
Based on the support matrix, elasticsearch 2.x is not compatible with x-pack.
You might want to install Watcher as a separate plugin using this document.

How to get elasticsearch suggestions working on multiple fields from multiple types?

I have a requirement to have a search box globally on the website that user can type anything in, a bit like google. As the user is typing along, he should get suggestions. I have multiple types in an Index, I am using Completion suggester to get suggestions from one field like below:
GET /index/_suggest/
{
"person-suggest" : {
"text" : "m",
"completion" : {
"field" : "nameSuggest"
}
}
}
The requirement is such that when they type a person name which is stored in person type or type in a company name which is stored in company type...both suggestions should appear. Also, within the same type, it should be able to suggest based on multiple fields not just one like what I've got. And finally once the user selects a suggestion, do a search and show facets which are based on multiple types.
For multi-type suggestions on multiple fields, use-
curl -XPOST 'localhost:9200/indexName/type1,type2/_suggest' -d '{
"my-suggestion-1" : {
"text" : "some text",
"term" : {
"field" : "field1"
}
},
"my-suggestion-2" : {
"text" : "some text",
"term" : {
"field" : "field2"
}
}
}'

Resources