Calling Elasticsearch Template Query using NEST? - templates

Is there a way to call Template Query using NEST? Is there any examples?

The search template endpoint isn't mapped in NEST yet, and poses a bit of a challenge since it's very different to how queries are normally constructed. We're actually working on this now (in this branch) and are hoping to get this functionality in the upcoming 1.1 release. Here's a link to the original issue for tracking purposes.
EDIT: Forgot to mention, the endpoint is available on the low-level Elasticsearch.Net client, which you can access via ElasticClient:
var client = new ElasticClient(...);
client.Raw.SearchTemplate(...);

The search template endpoint has been mapped in NEST 2.x.
There is a general example about templating here:
https://www.elastic.co/guide/en/elasticsearch/client/net-api/2.x/template-query-usage.html
Here is some information about how inline templates can be used in a phrase suggestion with the collate option:
https://www.elastic.co/guide/en/elasticsearch/client/net-api/2.x/suggest-usage.html
Here is an issue on GitHub I posted with some information on how to save templates to Elastic:
https://github.com/elastic/elasticsearch-net/issues/2176
Here's a general example of how to use NEST:
var templateRequest= new PutSearchTemplateDescriptor(new Id("my_template"));
templateRequest.Template("{\"multi_match\":{\"query\":{\"query\":\"{{suggestion}}\",\"fields\":[\"field1\",\"field2\"]}}}");
var response = ElasticClient.PutSearchTemplate(templateRequest);
When using the template in a suggest collate:
.Collate(c => c
.Query(q => q
.Indexed("my_template")
)
.Prune()
)

Another question on similiar lines, Is PutSearchTemplateDescriptor the write method to call a pre-regsitered template?
I have registered the template to the .scripts but unable to find the right method to call the template from NEST client

Related

HelloSign: how to duplicate a template though API?

The following screenshot is the manual approach to duplicate a template.
Is there an API to do it?
# API like this
HelloSignClient.duplicate_template(template_id)
This is Hazem from HelloSign API Support team.
Take a look at the /template endpoints - to replicate the "Duplicate" feature on hellosign.com for templates, you'd use GET /template/files (if you need the original files), and then POST /template/update_files. That creates a new template using the original template's overlay, and the "new" or the same documents that you pass in (which in this case would be files from your GET /template/files call).
For more details about this endpoint, please check the links below:
*Update Template Files
https://app.hellosign.com/api/reference#update_template_files
*Get Template Files
https://app.hellosign.com/api/reference#get_template_files

How do I get the date/requestTime/timestamp in Mapping Template

Looking at the documentation here it appears there is no way of getting the requestTime from the context variable.
Is there any other way, apart from using a lambda resolver, to get that value?
I know it is possible when using API Gateway, so surely there is a way. Am I looking at the wrong thing?
Thanks
Julien
(I work on the AWS AppSync team)
You're right, we do not yet expose the request time inside the mapping template.
May I ask what your use case is?
This is valuable feedback, I'm going to make sure this gets seen by the team. I will update this thread as we have more information.
UPDATE: We now support extracting the current timestamp via mapping template helper methods.
Here are a few functions that can help you achieve what you need:
$util.time.nowISO8601() : 2018-02-06T19:01:35.749Z
$util.time.nowEpochSeconds() : 1517943695
$util.time.nowEpochMilliSeconds() : 1517943695750
$util.time.nowFormatted("yyyy-MM-dd HH:mm:ssZ") : 2018-02-06 19:01:35+0000
$util.time.nowFormatted("yyyy-MM-dd HH:mm:ssZ", "+08:00") : 2018-02-07 03:01:35+0800
$util.time.nowFormatted("yyyy-MM-dd HH:mm:ssZ", "Australia/Perth") : 2018-02-07 03:01:35+0800
The complete reference is available on the Resolver Mapping Template Utility Reference page.

Can a Custom DataProvider class expose Custom Templates?

I am currently in the process of writing a custom DataProvider. Using the Intergrate External Data documentation.
I've managed to show the external data in the Sitecore back end. However whenever I try to view the data in the items I created, I am getting an error
Null ids are not allowed. <br> Parameter name: displayName
There seems to be precious little on the subject on how to create a custom DataProvider on the Sitecore Developer Network.
The example on their website seems to only show how to import a SINGLE item into a static database. However I am simply trying to merge some items into the hierarchy and I can't find any useful documentation.
It seems that one of your methods that should return an ID doesn't. It might be GetChildIds and/or GetParentId.
Nick Wesselman wrote a good article about it gathering all the information including an example on the Marketplace. I think that is your best start. You can read it here.
Turns out I needed to include at the very least, the Fields->Section->Template in the GetParent method. To be on the safe side I included the Fields/Sections/Templates into my implementations of
GetChildIDs
GetItemDefinition
GetParentID
It wasn't obvious that this was the case, since I had in fact implemented the GetTemplates method correctly, and I had expected that should be enough.

Emberjs New routing and query string or custom route matcher

I'm trying to migrate my app to the new emberjs routing API.
With old router I had some workarounds to provide similar URI for objects saved by ID and for new objects which described by set of params. This were done for ability of exchange links to objects between users without permanently saving it. This is two simplified valid routes from my app:
/objects/12 // fetch object by id (/objects/:object_id)
/objects/<serialized params> // build new object from params (/objects/:params)
Both of this routes are similar to router because they all have dynamic parts and static parts are equal. So I wrote custom RouteMatcher to pickup right route. Lack of query string parsing forced me to do this hack as quick and semilegal solution, also there is ancient ticket about this feature on github.
With the new router matching has been extracted to separate package (route-recognizer) so I cannot do the trick (or it will be full of hacks and injections).
As I can see I have to choose from these options:
Totally rewrite my URIs and separate all intersecting routes
Rewrite URIs but try to implement query string parser for the new Ember.Router
Put all logic into one route and reimplement only serialize/deserialize methods (something dirty)
Second solution seems to be more clean.
What will be the best non complicated decision? Should I try to find another way?
The current router does not support query-string parameters.
We are tracking this bug at https://github.com/emberjs/ember.js/issues/1773. You may want to follow it.
In the meantime, your best bet is probably to use a dynamic segment and manually serialize (with the serialize hook) and deserialize (with the model hook).

Joomla 2.5 ― using administrator components controllers in frontent part of component

how can I use the controllers created at
/administrator/components/com_mycom/controllers/*
in
/components/com_mycom/mycom.php
In detail:
I have a »log« controller with an »add« method, and I would like to use this from the frontend. I one is not logged in in the backend the task is not executed and a 500 error rises. So just would like to include the backend controllerpath in the frontend, so that JController::getInstance( 'Mycom' ) still works.
Greetings…
EDIT:
After a long time of searching I could find a more or less undocumented Parameter of the:
JController::getInstance() method, namely the second one: $config = array(). Going through the source code I found out that there is one key of the »config-array« that is of interest, which is: »base_path«.
The call of:
JController:getInstance( 'Mycom, array('base_path' =>JPATH_ADMINISTRATOR.DS.'components'.DS.'com_mycom')' );
always delivers the backend controller and one can use them safely in the frontend, BUT one must take care that then also the views are taken from the backend side of the component. In my case, I just use it to make ajax-calls so it does not matter, but one needs to be careful with using this method when planning to create »frontend views« with »backend controller«.
Greetings…
I had recently a similar problem where I wanted to use the whole CRUD system form back-end also in front-end.
This is the method that worked for me (and I am not saying that this is recommended or best practice):
I've just modeled the folders / file structure from backend. PHP files contained something like:
require_once JPATH_ADMINISTRATOR . '/components/com_mycom/controllers/log.php';