GET Index Schema from Azure Search - azure

I'm currently working on a POC that uses Azure Search to make an Angular Front End.
I've searched everywhere and am looking for a way to query for the index schema.
What do I mean by this? On this page you can use a PUT to create an index using JSON.
Is there a way to get this JSON schema back using a GET or using the Azure Portal? I want to be able to populate a NavBar with the facetable fields without having to hard code them. Is this possible?

You can call Get Index REST API to get the schema of an Index.
Your request URL would be:
https://[service name].search.windows.net/indexes/[index name]?api-version=[api-version]
You would need Admin Key to authenticate the Get Index request.
You will need to parse fields element from the response body to get the list of all attributes of the index.

Related

Algolia backend search or frontend search when an user ID is involved

I have my records stored in the Algolia index having a userID attribute associated with each. I want to perform a search such that the records visible to the user will be filtered such that the userIDs match. I can easily do this on the frontend using the instantsearch library and the userID stored in localStorage.
Problem with passing userID on the frontend
Anyone using the client can manipulate the Algolia request with different userIDs that will filter results relevant to those IDs. A security issue here. But as Algolia mentioned here frontend search can be upto 10x faster.
Solution using backend search
Can implement this such that a normal HTTP request is send to the backend with the relevant search parameters and filters and adding the userID in the backend. After that doing the search in the backend and sending the data back to the frontend using a HTTP response. Slower since it has go through multiple servers just to add the userID.
Question
I want to know if there is a still a workaround for this using frontend search and preserving security since speed is also important. I'm new to using Algolia and still not fully aware of what it is capable of.
Thanks.
There is a baked-in way to add user-based security for record access control.
You need to generate ephemeral API keys with filters hard coded. The end user cannot alter those filters to get around the security. When a user comes through your login flow, the backend generates this key with the appropriate filters (e.g. 'filters' => visible_by:group/'.$currentGroupId.' OR visible_by:group/Everybody' and passes it to the front end in places of the search-only API key.
Your records will need to include a matching attribute for the filter (visible_by in this case) with the appropriate values.
You can read more about it here:https://www.algolia.com/doc/guides/security/api-keys/how-to/user-restricted-access-to-data/#generating-a-secured-api-key

RestHeart Deleting Specific JSON object from Collection

The title explains most of it. I am trying to remove all objects from a collection where {"name": "Steve"} for example but I can't find anything in the documentation on how to achieve this without two separate http requests.
I am using NodeJS with the request library. All I have been able to find as a viable option is to find the ID and delete the object by using that.
Thanks for your help!
You can use a bulk delete request:
DELETE /db/coll/*?filter={"name":"Steve"}
Bulk requests have the URI with wildcard document id and include DELETE and PATCH verbs.
More info at https://softinstigate.atlassian.net/wiki/x/JQBGAQ

GETting a document within a Document Update Handler

Is it possible to query (GET) a document from within a document update handler in CouchDB?
I have written a simple document update handler in CouchDB 2.0 to accept a POST from a third party (CognitoForms). This works fine, and I take the ID from their JSON payload and use that as the doc _id.
You can then specify an 'update' URI in CognitoForms, so I could create a new update handler or use the same one. However, in CognitoForms:
The update does a POST rather than a PUT
There does not appear to be a way to send any query parameters
As the ID for the document which needs to be updated is within the body, I could use this to query the database for the document, get the _rev, and return the payload with the _id and _rev to perform the update. However, I simply don't know if I can do such a query within the update handler. I feel like I am either missing something obvious, or there is a very good reason that I wouldn't be allowed to do that.
Thanks very much
edit: I should add that I understand I could create a small application to parse the request before forwarding on to couchdb, but I was interested to see if I could implement this in couchdb only to understand how far I can get without another layer!
In your particular case, it's quite hard to do this. A document update handler is basically a pure function that gets the data it needs and returns a response, but it has no way to reach out into the database.
If you add a doc id to the url, the update function gets the doc from the database as a parameter. For details see the CouchDB docs for update functions.
The way to a possible solution is to use a rewrite in CouchDB in order to extract the id from the body. In CouchDB 2.0, a new way for rewrites as functions has been introduced.
For pushing the limits, using a rewrite function for this sounds like fun. But for a production use case, it's probably easier and more maintainable to create a small node.js app that parses the body.

Unable to get proper paginated data using API

Hello I have tried to extract paginated data using import.io. So far I have managed to retrieve JSON data by using Bulk Extract.
But I need it through the API, i.e. the export pane's API which is currently remaining unchanged even if I update the URLs via Bulk Extract.
Here is the url http://www.metalstorm.net/events/new_releases.php
I want to retrieve the new releases table with the album covers
Hoping to get a response soon

Sail.js - how to structure JSON based live data output with existing static data in the model

In my Angular app, I want to display a table which contains the following
a) URL
b) Social share counts divided by different social networks
Using Sails.js, I already have the api created for the URL when the results show up, I can display the URL now I'm confused how to get the appropriate social counts showing right besides
Here's the API I'm using: https://docs.sharedcount.com/
by itself, I can see the JSON it produces
But here are my questions:
Should I create a new api (model/controller) for social count data or include it in my model where I have the 'url' action defined?
If I create a new api or include the social_counts as an action in the current, what would my JSON query look like? to retrieve the URL's, I'm using default API blueprint that Sails provides, so:
http://www.example.com/url/find?where={"title":{"contains":"mark"}}
Struggling a bit in terms of the thought process, would be great to get input on this
It depends on your app. is your app will store that data or just consume it? If it need to store, of course you need the API. In purpose for modification or aggregating the data for example.
No, you can't do that. That shortcut method only works if you have the data in your database and let the Sails Waterline ORM and Blueprint API served it.
Perhaps, if you only need to consume the data from that Sharedcount API, you didn't need to use Sails as a backend, in this context. Just use Angular as a client of that API. Except if you need to modify the data first and store it in your own database, so Sails will helps with it's Waterline ORM and Blueprint API.

Resources