How can we improve Microsoft Azure Functions?

Search input/output bindings

Want to treat documents of the Azure Search as JSON from the Function Apps.

First about input bindings. See following pseudo function.json.

{
"bindings": [
{
"name": "req",
"type": "httpTrigger",
"direction": "in"
},
{
"name": "search_result",
"type": "search",
"direction": "in",
"serviceName": "mybookshelf",
"indexName": "book",
"apiKey": "envname-SEARCH_ADMIN_KEY",
"queryType": "full",
"searchMode": "all",
"searchFields": ["id", "title", "author"],
"search": "title:{title} AND genre:{genre}"
},
{
"name": "res",
"type": "http",
"direction": "out"
}
]
}

When an http request is arrived, contents of $search_result likes as followings.

[
{
"id": "e583e025-01f4-4288-8dec-be6723afe607",
"title": "Dragon Ball vol.1",
"author": "Akira TORIYAMA"
},
{
"id": "bb0086f9-e924-450c-b615-f51fb730e339",
"title": "Dragon Ball vol.2",
"author": "Akira TORIYAMA"
},
{
"id": "b3cf7892-1044-4b05-93dd-bea33f033e37",
"title": "Naruto vol.1",
"author": "Masashi KISHIMOTO"
},
{
"id": "b0f5231f-683b-4d8e-8a29-d1a7702f4b77",
"title": "Naruto vol.2",
"author":"Masashi KISHIMOTO"
},
{
"id": "51d83ac4-d075-4aa6-aaf1-92d752775022",
"title": "Jojo's bizzare adventure vol.1",
"author": "Hirohiko ARAKI"
}
]

Next about output bindings. See following pseudo function.json.

{
"bindings": [
{
"name": "req",
"type": "httpTrigger",
"direction": "in"
},
{
"name": "search_index",
"type": "search",
"direction": "out",
"serviceName": "mybookshelf",
"indexName": "book",
"apiKey": "envname-SEARCH_ADMIN_KEY"
},
{
"name": "res",
"type": "http",
"direction": "out"
}
]
}

And, See following pseudo index.js.

// pseudo uuid generator
function genUUID () {
...
}

// function logic
module.exports = function (context) {

// request
var req = context.req;

// parameters
var id = genUUID();
var title = req.query.title;
var author = req.query.author;

// new document
var doc = {
"@search.action": "upload",
"id": id,
"title": title,
"author": author
};

// add document(s) to search index
context.search_index = [ doc ];

// http response
context.res = {
"status": 200,
"body": {
"message": "done"
}
};
};

1 vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)

    We’ll send you updates on this idea

    Satoshi Azuma shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    1 comment

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...

      Feedback and Knowledge Base